:root {
  --paper: #F6F5F1;
  --card: #FFFFFF;
  --ink: #1C2B33;
  --muted: #6B7680;
  --line: #DDD9CE;
  --accent: #0E7C86;
  --accent-ink: #0A5A62;
  --amber: #E8B04B;
  --amber-soft: #FBF0DA;
  --danger: #B4483A;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: "Pretendard Variable", Pretendard, -apple-system, sans-serif;
  font-size: 16px; line-height: 1.65;
}
.mono { font-family: var(--mono); font-size: .86em; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- top bar + hex signature band ---- */
.topbar {
  display: flex; align-items: center; gap: 22px;
  padding: 10px 20px; background: var(--ink); color: #EDEAE2;
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff;
  font-weight: 750; letter-spacing: .02em; font-size: 17px; }
.brand .hex { color: var(--amber); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: #C9D2D6; padding: 7px 12px; border-radius: 7px; font-weight: 550; }
.topbar nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.who { display: flex; align-items: center; gap: 10px; color: #C9D2D6; }
.hexband {
  height: 7px;
  background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='7' viewBox='0 0 28 7'%3E%3Cpolygon points='7,0 14,3.5 7,7 0,3.5' fill='none' stroke='rgba(255,255,255,.45)' stroke-width='.8'/%3E%3Cpolygon points='21,0 28,3.5 21,7 14,3.5' fill='none' stroke='rgba(255,255,255,.2)' stroke-width='.8'/%3E%3C/svg%3E");
}

.wrap { max-width: 1060px; margin: 0 auto; padding: 26px 20px 80px; }
.flash { background: var(--amber-soft); border: 1px solid var(--amber);
  padding: 10px 14px; border-radius: 9px; margin-bottom: 16px; }

/* ---- buttons & inputs: tablet-sized targets ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer; text-decoration: none !important;
}
.btn:hover { background: var(--accent-ink); }
.btn.ghost { background: transparent; color: inherit; border-color: currentColor; opacity: .85; }
.btn.warn { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  min-height: 44px; padding: 8px 12px; border: 1px solid var(--line);
  border-radius: 9px; font: inherit; background: var(--card); color: inherit; width: 100%;
}
textarea { line-height: 1.6; }
label { font-weight: 600; font-size: 14px; display: block; margin: 14px 0 5px; }

.page-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 26px; font-weight: 780; letter-spacing: -.01em; margin: 0; flex: 1; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters select, .filters input { width: auto; min-width: 150px; }

/* ---- note list ---- */
.note-list { display: grid; gap: 10px; }
.note-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 18px; display: flex; align-items: center; gap: 14px;
}
.note-card .t { font-weight: 680; font-size: 17px; flex: 1; min-width: 0; }
.note-card .meta { color: var(--muted); font-family: var(--mono); font-size: 12.5px; text-align: right; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.badge.live { background: var(--amber-soft); color: #8a6414; border: 1px solid var(--amber); }
.badge.cm { background: #E8F2F3; color: var(--accent-ink); }

/* ---- editor ---- */
.editor-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.editor-head h1 { font-size: 21px; margin: 0; flex: 1; }
.save-state { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar button {
  min-height: 44px; min-width: 48px; padding: 0 12px; border: 1px solid var(--line);
  background: var(--card); border-radius: 9px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.toolbar button:active { background: #E8F2F3; }
.CodeMirror {
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  height: calc(100vh - 320px); min-height: 340px;
  font-family: var(--mono); font-size: 15px; line-height: 1.7; padding: 6px;
}
.cm-hintbox {
  position: absolute; z-index: 60; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 22px rgba(28,43,51,.14);
  max-height: 260px; overflow: auto; min-width: 240px;
}
.cm-hintbox div { padding: 11px 14px; cursor: pointer; }
.cm-hintbox div.sel, .cm-hintbox div:hover { background: #E8F2F3; }

/* ---- note view ---- */
.note-body {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 26px 30px; overflow-wrap: break-word;
}
.note-body h1, .note-body h2 { letter-spacing: -.01em; }
.note-body img.embed-img { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.note-body video.embed-video { max-width: 100%; border-radius: 10px; background: #000; }
.note-body table { border-collapse: collapse; }
.note-body th, .note-body td { border: 1px solid var(--line); padding: 6px 12px; }
.note-body pre { background: #F1EFE8; border-radius: 10px; padding: 12px 14px; overflow: auto; }
a.wikilink { font-weight: 650; border-bottom: 2px solid rgba(14,124,134,.35); }
a.wikilink.missing { color: var(--danger); border-bottom-style: dashed; }
a.file-card {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 15px; margin: 3px 0;
  border: 1px solid var(--line); border-radius: 10px; background: #FBFAF7; font-weight: 600;
}
a.file-card::before { content: "⬇"; color: var(--accent); }
mark.anchor-hl { background: var(--amber-soft); border-bottom: 2px solid var(--amber); }

.side-title { font-size: 14px; font-weight: 750; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); margin: 30px 0 10px; }
.backlinks a { display: inline-block; margin: 3px 6px 3px 0; }

/* ---- comments ---- */
.comment { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 12px 16px; margin-bottom: 10px; }
.comment.inline-c { border-left-color: var(--amber); }
.comment .c-head { display: flex; gap: 10px; align-items: baseline; }
.comment .c-head .a { font-weight: 700; }
.comment .c-head .d { color: var(--muted); font-family: var(--mono); font-size: 12px; flex: 1; }
.comment .anchor-quote { font-size: 13.5px; color: var(--muted); background: var(--amber-soft);
  border-radius: 7px; padding: 5px 10px; margin: 7px 0; cursor: pointer; }
.comment .anchor-quote::before { content: "❝ "; }
.comment .c-files { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.comment .c-files img { max-height: 160px; border-radius: 8px; border: 1px solid var(--line); }
.comment-form { background: var(--card); border: 1px dashed var(--line); border-radius: 12px; padding: 16px; }
#selection-bar {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; border-radius: 12px; padding: 10px 16px;
  display: none; gap: 12px; align-items: center; z-index: 50;
  box-shadow: 0 10px 26px rgba(28,43,51,.35); max-width: 92vw;
}
#selection-bar .q { font-size: 13px; opacity: .8; max-width: 320px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }

/* ---- daily diff ---- */
.day-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.day-pills a { border: 1px solid var(--line); background: var(--card); border-radius: 22px;
  padding: 8px 15px; font-family: var(--mono); font-size: 13px; }
.day-pills a.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.diff-box { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 18px; margin-bottom: 16px; font-family: var(--mono); font-size: 13.5px;
  overflow-x: auto; }
.diff-add { background: #E7F3EC; color: #1B5E36; padding: 1px 8px; border-left: 3px solid #2E9E5B; }
.diff-del { background: #FBEBE8; color: #8C3327; padding: 1px 8px; border-left: 3px solid var(--danger); text-decoration: line-through; }
.diff-ctx { color: var(--muted); padding: 1px 8px; border-left: 3px solid transparent; }
.muted { color: var(--muted); }

/* ---- graph ---- */
#graph-box { background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  height: calc(100vh - 220px); min-height: 460px; }

/* ---- admin ---- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.panel h2 { font-size: 16px; margin: 0 0 12px; }
.feed { max-height: 420px; overflow: auto; }
.feed-item { padding: 9px 4px; border-bottom: 1px solid #EFEDE6; font-size: 14px; }
.feed-item .mono { color: var(--muted); }
.feed-item.new { animation: pop .5s ease; }
@keyframes pop { from { background: var(--amber-soft); } to { background: transparent; } }
table.plain { width: 100%; border-collapse: collapse; }
table.plain td, table.plain th { padding: 8px 6px; border-bottom: 1px solid #EFEDE6; text-align: left; font-size: 14px; }

.auth-box { max-width: 420px; margin: 8vh auto; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; padding: 30px 32px; }
.auth-box h1 { margin-top: 0; }

@media (max-width: 760px) {
  .grid2 { grid-template-columns: 1fr; }
  .note-body { padding: 18px; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .CodeMirror { height: 55vh; }
}
@media (prefers-reduced-motion: reduce) {
  .feed-item.new { animation: none; }
}

/* ---- 단일 편집창: 섹션 구획 디자인 ---- */
.sec-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; font-family: var(--mono); font-size: 13px;
  color: #fff; background: var(--accent); flex: none;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
.sec-nav { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.sec-nav button {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card); font-size: 15px; font-weight: 650;
  cursor: pointer;
}
.sec-nav button:active { background: #E8F2F3; }
/* 편집기 내부의 섹션 제목 줄 */
.CodeMirror .cm-sec-line {
  background: #EDF4F4 !important;
  border-left: 4px solid var(--accent);
  border-radius: 0 8px 8px 0;
  font-weight: 750; font-size: 16px;
  padding: 7px 10px 7px 40px !important;
  margin: 10px 0 4px;
  position: relative;
}
.CodeMirror .cm-sec-line::before {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  color: #fff; background: var(--accent); font-size: 12px; font-weight: 700;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
.CodeMirror .cm-sec-1::before { content: "1"; }
.CodeMirror .cm-sec-2::before { content: "2"; }
.CodeMirror .cm-sec-3::before { content: "3"; }
.CodeMirror .cm-sec-line .cm-header { color: var(--ink); }

/* 열람 화면: 섹션 제목 강조 */
.note-body h1 {
  font-size: 19px; padding: 6px 0 6px 12px; margin-top: 26px;
  border-left: 4px solid var(--accent); background: #F4F8F8;
  border-radius: 0 8px 8px 0;
}
.note-body h1:first-child { margin-top: 0; }

/* ---- 계층 트리 ---- */
.note-card.depth-1 { margin-left: 26px; }
.note-card.depth-2 { margin-left: 52px; }
.note-card.depth-3 { margin-left: 78px; }
.note-card.depth-4 { margin-left: 104px; }
.note-card.depth-5 { margin-left: 130px; }
.tree-tick { color: var(--muted); font-family: var(--mono); margin-right: 7px; }
.crumb { font-size: 14px; margin-bottom: 10px; color: var(--muted); }
.crumb .sep { margin: 0 7px; }
@media (max-width: 760px) {
  .note-card.depth-1 { margin-left: 14px; }
  .note-card.depth-2 { margin-left: 28px; }
  .note-card.depth-3 { margin-left: 42px; }
  .note-card.depth-4 { margin-left: 56px; }
  .note-card.depth-5 { margin-left: 70px; }
}

/* ---- 트리 접기/펼치기 ---- */
.tw {
  flex: none; width: 34px; height: 34px; border: 1px solid var(--line);
  border-radius: 8px; background: #FBFAF7; color: var(--accent-ink);
  font-family: var(--mono); font-size: 17px; font-weight: 700; line-height: 1;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.tw:hover { background: #E8F2F3; }
.tw-space { flex: none; width: 34px; text-align: center;
  color: var(--muted); font-family: var(--mono); }
.row-hidden { display: none; }

/* ---- 상위 노트 트리 선택기 ---- */
.pp { position: relative; }
.pp-btn {
  width: 100%; min-height: 44px; padding: 8px 36px 8px 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 9px; background: var(--card);
  font: inherit; cursor: pointer; position: relative;
}
.pp-btn::after {
  content: "▾"; position: absolute; right: 13px; top: 50%;
  transform: translateY(-50%); color: var(--muted);
}
.pp-panel {
  position: absolute; z-index: 30; left: 0; right: 0; margin-top: 5px;
  background: var(--card); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: 0 10px 26px rgba(28,43,51,.16); max-height: 320px; overflow: auto;
  padding: 5px;
}
.pp-row {
  display: flex; align-items: center; gap: 8px; min-height: 44px;
  padding: 4px 8px; border-radius: 8px; cursor: pointer;
}
.pp-row:hover { background: #F1F6F6; }
.pp-row.pp-on { background: #E8F2F3; font-weight: 650; }
.pp-depth-1 { padding-left: 30px; }
.pp-depth-2 { padding-left: 54px; }
.pp-depth-3 { padding-left: 78px; }
.pp-depth-4 { padding-left: 102px; }
.pp-depth-5 { padding-left: 126px; }
.pp-tw {
  flex: none; width: 30px; height: 30px; border: 1px solid var(--line);
  border-radius: 7px; background: #FBFAF7; color: var(--accent-ink);
  font-family: var(--mono); font-size: 15px; font-weight: 700;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.pp-tw:hover { background: #E8F2F3; }
.pp-space { flex: none; width: 30px; text-align: center;
  color: var(--muted); font-family: var(--mono); }
.pp-hidden { display: none; }

/* ---- 인라인 표 편집기 (노션식) ---- */
.tblw {
  margin: 8px 0; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); overflow: hidden;
}
.tblw-bar {
  display: flex; gap: 5px; align-items: center;
  padding: 6px 8px; background: #F4F6F5; border-bottom: 1px solid var(--line);
}
.tblw-bar button {
  min-height: 34px; padding: 0 11px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--card); font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.tblw-bar button:active { background: #E8F2F3; }
.tblw-sp { flex: 1; }
.tblw-del { color: var(--danger); }
.tblw-grid { border-collapse: collapse; width: 100%; }
.tblw-grid th, .tblw-grid td {
  border: 1px solid var(--line); min-width: 80px; padding: 9px 12px;
  font-family: "Pretendard Variable", Pretendard, sans-serif; font-size: 15px;
  outline: none; caret-color: var(--accent);
}
.tblw-grid th { background: #EDF4F4; font-weight: 700; text-align: left; }
.tblw-grid td:focus, .tblw-grid th:focus { box-shadow: inset 0 0 0 2px var(--accent); }

/* ---- 셀 안 이미지 & 이미지 설정 패널 ---- */
.tblw-img { max-width: 100%; max-height: 220px; display: block; margin: 4px 0;
  border-radius: 6px; cursor: pointer; }
.tblw-img:hover { outline: 2px solid var(--accent); }
.img-pop {
  position: absolute; z-index: 120; width: 330px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 14px 34px rgba(28,43,51,.25); padding: 12px 14px;
  font-size: 14px;
}
.img-pop[hidden] { display: none; }
.ip-row { display: flex; align-items: center; gap: 7px; margin: 7px 0; flex-wrap: wrap; }
.ip-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 100%; color: var(--accent-ink); }
.ip-row input.ip-w { width: 84px; min-height: 38px; }
.ip-row select.ip-q { width: auto; min-height: 38px; flex: 1; }
.ip-row button {
  min-height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px;
  background: #FBFAF7; font-size: 13px; font-weight: 600; cursor: pointer;
}
.ip-row button:active { background: #E8F2F3; }
.ip-end { justify-content: flex-end; }
.ip-msg { flex: 1; color: var(--accent-ink); font-family: var(--mono); font-size: 12px; }

/* ---- 열람 화면: 이미지 크기/정렬 ---- */
.note-body img.embed-center { display: block; margin: 10px auto; }
.note-body img.embed-left { float: left; margin: 4px 16px 10px 0; }
.note-body img.embed-right { float: right; margin: 4px 0 10px 16px; }
.note-body::after { content: ""; display: block; clear: both; }
.note-body td img.embed-img { max-height: 240px; }

.app-ver { text-align: center; color: #B8B4A8; font-size: 11px; padding: 20px 0 26px; }

/* ---- 본문 이미지 미리보기 ---- */
.cm-img-preview { padding: 4px 8px 8px 8px; }
.cm-img-preview img {
  border-radius: 8px; border: 1px solid var(--line); display: inline-block;
  margin-right: 8px; vertical-align: top;
}
.cm-img-preview.prev-center { text-align: center; }
.cm-img-preview.prev-right { text-align: right; }

.tblw-w { display: inline-flex; align-items: center; gap: 5px; font-size: 13px;
  color: var(--muted); }
.tblw-w select { min-height: 34px; width: auto; padding: 4px 8px; font-size: 13px; }
.tblw-grid { width: auto; min-width: 50%; }
