:root {
  --top: #24534f;
  --top-ink: #f3efe6;
  --chrome: #f6f3ec;
  --side: #ece6da;
  --pages: #f3eee5;
  --sheet: #fffefa;
  --ink: #26231e;
  --muted: #80786c;
  --line: #ddd4c4;
  --line-soft: #e9e2d5;
  --accent: #2f6f6a;
  --accent-soft: #e2eeec;
  --danger: #b4432f;
  --ui-font: "Pretendard", "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
  --note-font: "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--ui-font);
  font-size: 13px;
  color: var(--ink);
  background: var(--chrome);
  display: grid;
  grid-template-rows: 46px auto 1fr 26px;
  --sw: 232px; --pw: 250px;
  grid-template-columns: var(--sw) var(--pw) 1fr;
  grid-template-areas: "top top top" "tool tool tool" "side pages main" "status status status";
  overflow: hidden;
  user-select: none;
}
body.panes-hidden { grid-template-columns: 0 0 1fr; }
body.panes-hidden #sidebar, body.panes-hidden #pagesPane { display: none; }
button { font-family: inherit; font-size: inherit; color: inherit; }
svg.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Top bar ---------- */
#topbar {
  grid-area: top; display: flex; align-items: center; gap: 10px;
  background: var(--top); color: var(--top-ink); padding: 0 12px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.brand img { width: 24px; height: 24px; }
#crumb { flex: 1; text-align: center; opacity: .85; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#crumb .sep { opacity: .5; margin: 0 6px; }
.tb-icon {
  background: transparent; border: 0; border-radius: 6px; width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: inherit;
}
.tb-icon:hover { background: rgba(255,255,255,.12); }
.tb-icon.small { width: 26px; height: 26px; }
.pane-head .tb-icon:hover { background: rgba(0,0,0,.07); }

.search-wrap { position: relative; width: 320px; display: flex; align-items: center; }
.search-wrap > svg { position: absolute; left: 10px; width: 16px; height: 16px; opacity: .7; }
#search {
  width: 100%; height: 30px; border-radius: 15px; border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.12); color: var(--top-ink); padding: 0 12px 0 32px; font-family: inherit; font-size: 13px; outline: none;
}
#search::placeholder { color: rgba(243,239,230,.6); }
#search:focus { background: #fff; color: var(--ink); border-color: #fff; }
#search:focus + #searchResults:not([hidden]) { display: block; }
.search-wrap:focus-within > svg { color: var(--muted); opacity: 1; }
#searchResults {
  position: absolute; top: 36px; right: 0; width: 440px; max-height: 70vh; overflow: auto;
  background: #fff; color: var(--ink); border-radius: 10px; box-shadow: 0 12px 36px rgba(30,25,15,.25); z-index: 1000; padding: 6px;
}
.sr-item { padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.sr-item:hover, .sr-item.kb { background: var(--accent-soft); }
.sr-title { font-weight: 600; font-size: 13.5px; }
.sr-path { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.sr-snip { color: #4a463f; font-size: 12px; margin-top: 3px; line-height: 1.45; }
.sr-item mark { background: #ffe58a; color: inherit; border-radius: 2px; }
.sr-empty { padding: 14px; color: var(--muted); text-align: center; }

/* ---------- Toolbar ---------- */
#toolbar {
  grid-area: tool; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px;
  padding: 5px 10px; background: var(--chrome); border-bottom: 1px solid var(--line);
}
#toolbar .grp { display: flex; align-items: center; gap: 1px; padding-right: 6px; margin-right: 2px; border-right: 1px solid var(--line-soft); }
#toolbar .grp:last-child { border-right: 0; }
#toolbar .spacer { flex: 1; }
#toolbar button {
  height: 30px; min-width: 30px; padding: 0 6px; border: 1px solid transparent; border-radius: 6px; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 3px; cursor: pointer; font-size: 14px;
}
#toolbar button:hover { background: #ebe5d8; }
#toolbar button.on { background: var(--accent-soft); border-color: #bcd6d2; color: var(--accent); }
#toolbar button:disabled { opacity: .35; pointer-events: none; }
#toolbar button.wide { min-width: 92px; justify-content: space-between; font-size: 12.5px; }
#toolbar button.mid { min-width: 48px; justify-content: space-between; font-size: 12.5px; }
#toolbar button svg[data-k="chev"] { width: 12px; height: 12px; opacity: .6; }
#toolbar .ital { font-style: italic; font-family: serif; }
.swatch-btn { display: inline-flex; flex-direction: column; align-items: center; line-height: 1; }
.swatch-btn .ab { font-weight: 700; font-size: 14px; }
.swatch-btn svg { width: 16px; height: 16px; }
.swatch-btn .bar { width: 16px; height: 3px; border-radius: 2px; margin-top: 2px; }
.ink-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }

/* ---------- Sidebar ---------- */
.pane-head {
  display: flex; align-items: center; justify-content: space-between; height: 38px; padding: 0 8px 0 14px;
  font-weight: 700; font-size: 12px; letter-spacing: .4px; color: var(--muted); flex: none;
}
#sidebar { grid-area: side; background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#nbTree { flex: 1; overflow: auto; padding: 0 6px 10px; }
.nb-row, .sec-row, .sec-add {
  display: flex; align-items: center; gap: 7px; padding: 6px 8px; border-radius: 7px; cursor: pointer; white-space: nowrap;
}
.nb-row { font-weight: 600; margin-top: 4px; }
.nb-row:hover, .sec-row:hover { background: rgba(0,0,0,.05); }
.nb-row .caret { width: 12px; color: var(--muted); font-size: 10px; text-align: center; }
.nb-icon { width: 14px; height: 18px; border-radius: 2px 4px 4px 2px; flex: none; box-shadow: inset 3px 0 0 rgba(0,0,0,.18); }
.label { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.sec-list { margin-left: 18px; }
.sec-row .sec-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.sec-row .count { color: var(--muted); font-size: 11px; }
.sec-row.active { background: #fffaf0; box-shadow: 0 1px 2px rgba(60,50,30,.12); font-weight: 600; }
.sec-row.drop { outline: 2px dashed var(--accent); }
.sec-add { color: var(--muted); font-size: 12px; }
.sec-add:hover { color: var(--accent); }
.sb-foot { border-top: 1px solid var(--line); padding: 6px; }
.sb-foot button {
  width: 100%; display: flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 7px 8px; border-radius: 7px; cursor: pointer; color: var(--muted);
}
.sb-foot button:hover, .sb-foot button.active { background: rgba(0,0,0,.06); color: var(--ink); }
.sb-foot .count { margin-left: auto; font-size: 11px; }
input.rename {
  flex: 1; min-width: 0; font: inherit; border: 1px solid var(--accent); border-radius: 5px; padding: 2px 5px; outline: none; background: #fff; user-select: text;
}

/* ---------- Pages pane ---------- */
#pagesPane { grid-area: pages; background: var(--pages); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#pagesHead { border-left: 4px solid transparent; color: var(--ink); font-size: 13px; letter-spacing: 0; }
#paneTitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#pageList { flex: 1; overflow: auto; padding: 2px 6px 16px; }
.page-row { padding: 7px 10px; border-radius: 7px; cursor: pointer; border-left: 3px solid transparent; margin-bottom: 1px; }
.page-row:hover { background: rgba(0,0,0,.045); }
.page-row.active { background: #fffdf7; border-left-color: var(--sec, var(--accent)); box-shadow: 0 1px 2px rgba(60,50,30,.1); }
.page-row .pt { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-row .pt.untitled { color: var(--muted); font-style: italic; }
.page-row .pd { font-size: 11px; color: var(--muted); margin-top: 2px; }
.page-row.lvl1 { margin-left: 16px; }
.page-row.lvl2 { margin-left: 32px; }
.page-row.dragging { opacity: .4; }
.page-row.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.page-row.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.trash-row { padding: 9px 10px; border-radius: 7px; background: #fffdf7; margin-bottom: 6px; box-shadow: 0 1px 2px rgba(60,50,30,.08); }
.trash-row .pt { font-weight: 600; }
.trash-row .pd { font-size: 11px; color: var(--muted); margin: 2px 0 6px; }
.trash-row .acts { display: flex; gap: 6px; }

.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: 12.5px; }
.btn:hover { background: #f5f1e8; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #285f5b; }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.ghost-danger { color: var(--danger); }

/* ---------- Editor ---------- */
#editorPane { grid-area: main; position: relative; min-width: 0; min-height: 0; background: #e9e4d9; }
#canvasScroll { position: absolute; inset: 0; overflow: auto; }
#canvasScroll[hidden] { display: none; }
#sheet { position: relative; background: var(--sheet); min-width: 100%; min-height: 100%; }
#sheet[data-paper="lines"] {
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 26px, #dde6ee 26px, #dde6ee 27px);
  background-position: 0 120px; background-repeat: repeat;
}
#sheet[data-paper="grid"] {
  background-image: linear-gradient(to right, #e6ecf1 1px, transparent 1px), linear-gradient(to bottom, #e6ecf1 1px, transparent 1px);
  background-size: 22px 22px;
}
#pageTitle {
  position: absolute; left: 48px; top: 30px; width: min(640px, calc(100% - 96px)); height: 46px;
  border: 0; border-bottom: 1px solid #cfc6b5; background: transparent; outline: none;
  font-family: var(--note-font); font-size: 26px; font-weight: 600; color: var(--ink); padding: 0 2px; user-select: text;
}
#pageTitle::placeholder { color: #bfb7a8; font-weight: 400; }
#pageDate { position: absolute; left: 50px; top: 84px; color: var(--muted); font-size: 12px; }
#items { position: absolute; inset: 0; }
#ink { position: absolute; left: 0; top: 0; z-index: 900; pointer-events: none; overflow: visible; }
body.drawing #ink { pointer-events: auto; cursor: crosshair; }
body.erasing #ink { pointer-events: auto; cursor: cell; }
#ink path.hl { mix-blend-mode: multiply; }

.item { position: absolute; }
.item.text { min-width: 120px; }
.item.text:hover { outline: 1px dashed #cfc5b3; outline-offset: 2px; }
.item.text:focus-within { outline: 1px solid #a9c4c0; outline-offset: 2px; }
.item.selected { outline: 2px solid var(--accent) !important; outline-offset: 2px; }
.item .grip {
  position: absolute; left: -3px; right: -3px; top: -15px; height: 12px; border-radius: 4px 4px 0 0;
  background: #dbe8e6 radial-gradient(circle, #8fb0ab 1px, transparent 1.4px) 0 0 / 6px 6px; cursor: move; display: none;
}
.item.text:hover .grip, .item.text:focus-within .grip, .item.text.selected .grip { display: block; }
.item .rsz-w { position: absolute; top: 0; right: -6px; width: 8px; height: 100%; cursor: ew-resize; display: none; }
.item.text:hover .rsz-w, .item.text:focus-within .rsz-w { display: block; }
.item .rsz-w::after { content: ""; position: absolute; top: 50%; left: 3px; width: 2px; height: 22px; margin-top: -11px; border-radius: 1px; background: #a9c4c0; }

.content {
  outline: none; min-height: 1.55em; padding: 2px 4px; font-family: var(--note-font); font-size: 15px; line-height: 1.6;
  color: var(--ink); overflow-wrap: anywhere; user-select: text; cursor: text;
}
.content p { margin: 0; }
.content h1 { font-size: 1.6em; margin: .15em 0; font-weight: 700; line-height: 1.35; }
.content h2 { font-size: 1.3em; margin: .15em 0; font-weight: 700; line-height: 1.4; }
.content h3 { font-size: 1.1em; margin: .1em 0; font-weight: 700; }
.content blockquote { margin: .2em 0; border-left: 3px solid #a9c4c0; padding-left: 10px; color: #5d574e; }
.content pre { background: #f3efe6; padding: 6px 8px; border-radius: 5px; font-family: Consolas, "D2Coding", monospace; font-size: 13px; white-space: pre-wrap; margin: .2em 0; }
.content ul, .content ol { margin: .1em 0; padding-left: 1.6em; }
.content a { color: #1b62c4; text-decoration: underline; }
.content hr { border: 0; border-top: 1px solid #cdc4b3; margin: .5em 0; }
.content img { max-width: 100%; height: auto; }
.content table.nt { border-collapse: collapse; margin: .3em 0; }
.content table.nt td, .content table.nt th { border: 1px solid #bdb3a1; padding: 4px 8px; min-width: 70px; vertical-align: top; }
.content table.nt tr:first-child td { background: #f4f0e7; font-weight: 600; }

.item.image img { display: block; width: 100%; height: auto; user-select: none; cursor: move; }
.item.image:hover { outline: 1px dashed #cfc5b3; outline-offset: 2px; }
.item .rsz { position: absolute; width: 14px; height: 14px; border-radius: 4px; background: #fff; border: 2px solid var(--accent); display: none; box-shadow: 0 1px 3px rgba(0,0,0,.2); z-index: 2; }
.item .rsz.c-se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.item .rsz.c-nw { left: -7px; top: -7px; cursor: nwse-resize; }
.item .rsz.c-ne { right: -7px; top: -7px; cursor: nesw-resize; }
.item .rsz.c-sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.item.image:hover .rsz.c-se, .item.image.selected .rsz { display: block; }
.item.image img { object-fit: fill; }

/* Tags */
.tag { display: inline-block; width: 16px; height: 16px; margin-right: 6px; vertical-align: -2px; user-select: none; position: relative; }
.tag-todo { border: 1.7px solid #5d6b78; border-radius: 4px; cursor: pointer; background: #fff; }
.tag-todo:hover { border-color: var(--accent); }
.tag-todo.done { background: var(--accent); border-color: var(--accent); }
.tag-todo.done::after { content: ""; position: absolute; left: 4px; top: 0.5px; width: 4px; height: 8.5px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.tag-important::before { content: "★"; position: absolute; inset: 0; color: #e0a10b; font-size: 16px; line-height: 16px; text-align: center; }
.tag-question::before { content: "?"; position: absolute; inset: 0; background: #7a5cc0; color: #fff; border-radius: 50%; font-size: 11px; font-weight: 800; line-height: 16px; text-align: center; font-family: Arial, sans-serif; }

::highlight(search) { background-color: #ffe066; }

#emptyState { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted); font-size: 14px; }
#emptyState[hidden] { display: none; }
#emptyState .big { font-size: 17px; color: var(--ink); font-weight: 600; }

/* ---------- Status bar ---------- */
#statusbar { grid-area: status; display: flex; align-items: center; gap: 14px; padding: 0 10px; background: var(--chrome); border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px; }
#statusbar .hint { flex: 1; }
#saveStatus.err { color: var(--danger); font-weight: 600; }
.zoom { display: flex; align-items: center; gap: 2px; }
.zoom button { border: 0; background: transparent; cursor: pointer; padding: 1px 7px; border-radius: 4px; color: var(--ink); font-size: 12px; }
.zoom button:hover { background: #e7e1d4; }
#zoomLabel { min-width: 46px; }

/* ---------- Menus, popovers, modals ---------- */
.ctx, .pop {
  position: fixed; z-index: 3000; background: #fff; border-radius: 9px; box-shadow: 0 10px 32px rgba(30,25,15,.22), 0 0 0 1px rgba(0,0,0,.05);
  padding: 5px; min-width: 180px; font-size: 13px; color: var(--ink);
}
.ctx-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.ctx-item:hover, .ctx-item.open { background: var(--accent-soft); }
.ctx-item.danger { color: var(--danger); }
.ctx-item.disabled { opacity: .4; pointer-events: none; }
.ctx-item .lbl { flex: 1; }
.ctx-item .hint { color: var(--muted); font-size: 11.5px; }
.ctx-item .arr { color: var(--muted); font-size: 10px; }
.ctx-item .sw { width: 12px; height: 12px; border-radius: 3px; }
.ctx .sep { height: 1px; background: var(--line-soft); margin: 4px 2px; }
.pop .opt { padding: 6px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.pop .opt:hover { background: var(--accent-soft); }
.pop .opt.cur { font-weight: 700; color: var(--accent); }
.pop .ttl { font-size: 11px; color: var(--muted); padding: 4px 6px 2px; font-weight: 600; }
.pop .swatches { display: grid; grid-template-columns: repeat(8, 22px); gap: 5px; padding: 6px; }
.pop .swatches span { width: 22px; height: 22px; border-radius: 5px; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.pop .swatches span:hover { transform: scale(1.12); }
.pop .swatches span.cur { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.pop .widths { display: flex; gap: 6px; padding: 6px; }
.pop .widths span { width: 34px; height: 30px; border-radius: 6px; display: flex; align-items: center; justify-content: center; cursor: pointer; border: 1px solid var(--line-soft); }
.pop .widths span.cur { border-color: var(--accent); background: var(--accent-soft); }
.pop .widths i { display: block; background: #333; border-radius: 4px; width: 18px; }

.modal-back { position: fixed; inset: 0; background: rgba(30,26,20,.32); z-index: 4000; display: flex; align-items: center; justify-content: center; }
.modal { background: #fff; border-radius: 12px; padding: 20px 22px 16px; width: 400px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 10px; font-size: 15px; }
.modal p { margin: 0 0 16px; line-height: 1.55; white-space: pre-line; }
.modal input[type=text] { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 7px; padding: 0 10px; font: inherit; outline: none; margin-bottom: 16px; user-select: text; }
.modal input[type=text]:focus { border-color: var(--accent); }
.modal .btns { display: flex; justify-content: flex-end; gap: 8px; }
.modal table.keys { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 12.5px; }
.modal table.keys td { padding: 4px 0; border-bottom: 1px solid var(--line-soft); }
.modal table.keys td:first-child { color: var(--muted); width: 48%; }
.modal kbd { background: #f3efe6; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-family: inherit; font-size: 11.5px; }

#toast {
  position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%) translateY(10px); background: #2b2823; color: #fff; padding: 8px 16px;
  border-radius: 8px; font-size: 12.5px; opacity: 0; transition: opacity .18s, transform .18s; pointer-events: none; z-index: 5000;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

body.dragging, body.dragging * { cursor: move !important; user-select: none !important; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: #cfc6b5; border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: #b7ad99; }
::-webkit-scrollbar-corner { background: transparent; }


/* ---------- Recording ---------- */
#toolbar button.recording { color: #c62828; background: #fbe9e7; border-color: #f3c3bb; }
#recBar {
  position: fixed; right: 18px; bottom: 40px; z-index: 2500; display: flex; align-items: center; gap: 8px;
  background: #2b2823; color: #fff; border-radius: 24px; padding: 6px 8px 6px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 13px;
}
#recBar .dot { width: 10px; height: 10px; border-radius: 50%; background: #ef5350; animation: recPulse 1.2s ease-in-out infinite; }
#recBar.paused .dot { background: #9e9e9e; animation: none; }
#recBar .t { font-variant-numeric: tabular-nums; min-width: 44px; }
#recBar .rec-where { background: none; border: 0; color: #fff; cursor: pointer; padding: 0; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#recBar .rb { width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(255,255,255,.12); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
#recBar .rb:hover { background: rgba(255,255,255,.22); }
#recBar .rb.stop { background: #e53935; }
#recBar .rb svg { width: 16px; height: 16px; }
@keyframes recPulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { #recBar .dot { animation: none; } }

.item.audio { min-width: 240px; }
.item.audio:hover .grip, .item.audio.selected .grip { display: block; }
.aud {
  display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid #d9d0bf; border-radius: 12px; padding: 8px 12px 8px 8px;
  box-shadow: 0 1px 3px rgba(60,50,30,.1); user-select: none;
}
.aud .aplay { width: 36px; height: 36px; flex: none; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.aud .aplay svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.aud .ainfo { flex: 1; min-width: 0; }
.aud .aname { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aud .abar { height: 14px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.aud .abar::before { content: ""; display: block; height: 4px; width: 100%; border-radius: 2px; background: #e6dfd2; }
.aud .afill { position: absolute; height: 4px; border-radius: 2px; background: var(--accent); width: 0; pointer-events: none; }
.aud .abar { position: relative; }
.aud .afill { left: 0; top: 5px; }
.aud .atime { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.aud .arate { font-size: 11px; color: var(--accent); font-weight: 700; }
.item.audio.is-recording .aplay { background: #e53935; animation: recPulse 1.2s ease-in-out infinite; }
.item.audio.is-recording .abar { opacity: .4; pointer-events: none; }

/* 녹음 시점이 연결된 줄 */
.content [data-t] { position: relative; }
.content [data-t]::before {
  content: ""; position: absolute; left: -24px; top: .2em; width: 18px; height: 18px; border-radius: 50%; cursor: pointer; opacity: .28;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M9 7v10l8-5z'/%3E%3C/svg%3E") center / 14px no-repeat;
}
.content [data-t]:hover::before, .item.text:focus-within .content [data-t]::before { opacity: .9; }
.content li[data-t]::before { left: -42px; }

/* ---------- Touch / pen ---------- */
.item .grip, .item .rsz, .item .rsz-w { touch-action: none; }
.item.image.selected img { touch-action: none; }
body.drawing #ink, body.erasing #ink { touch-action: none; }
.pop .toggle { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--line-soft); margin-top: 4px; cursor: pointer; white-space: nowrap; }
.pop .toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
#backdrop { display: none; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  body { grid-template-columns: 0 0 1fr; grid-template-rows: calc(46px + env(safe-area-inset-top)) auto 1fr calc(26px + env(safe-area-inset-bottom)); }
  #topbar { padding-top: env(safe-area-inset-top); gap: 6px; padding-left: 6px; padding-right: 8px; }
  .brand span, #crumb { display: none; }
  .search-wrap { flex: 1; width: auto; }
  #search { font-size: 16px; height: 32px; }
  #searchResults { position: fixed; top: calc(50px + env(safe-area-inset-top)); left: 8px; right: 8px; width: auto; }
  #toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 4px 6px; -webkit-overflow-scrolling: touch; }
  #toolbar::-webkit-scrollbar { display: none; }
  #toolbar .grp { flex: none; }
  #toolbar .spacer { display: none; }
  #toolbar button { height: 38px; min-width: 38px; }
  #sidebar, #pagesPane { display: none; }
  body.drawer-open #sidebar, body.drawer-open #pagesPane {
    display: flex; position: fixed; left: 0; width: min(88vw, 360px); z-index: 2200; box-shadow: 6px 0 24px rgba(0,0,0,.18);
  }
  body.drawer-open #sidebar { top: calc(46px + env(safe-area-inset-top)); height: 42vh; border-bottom: 1px solid var(--line); }
  body.drawer-open #pagesPane { top: calc(46px + env(safe-area-inset-top) + 42vh); bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
  body.drawer-open #backdrop { display: block; position: fixed; inset: 0; background: rgba(20,18,14,.35); z-index: 2100; }
  body.panes-hidden #sidebar, body.panes-hidden #pagesPane { display: none; }
  body.drawer-open.panes-hidden #sidebar, body.drawer-open.panes-hidden #pagesPane { display: flex; }
  .nb-row, .sec-row, .sec-add, .page-row { padding-top: 10px; padding-bottom: 10px; }
  #pageTitle { left: 18px; width: calc(100% - 36px); font-size: 22px; top: 18px; height: 40px; }
  #pageDate { left: 20px; top: 64px; }
  #statusbar { padding-bottom: env(safe-area-inset-bottom); }
  #statusbar .hint { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  #recBar { right: 10px; left: 10px; bottom: calc(34px + env(safe-area-inset-bottom)); justify-content: space-between; }
  .modal { width: calc(100vw - 32px); }
  .modal input[type=text] { font-size: 16px; }
  .content [data-t]::before { opacity: .7; }
  * { -webkit-tap-highlight-color: transparent; }
  .page-row, .nb-row, .sec-row, .item { -webkit-touch-callout: none; }
}


/* ---------- Toolbar glyphs ---------- */
#toolbar .supsub { font-size: 14px; font-family: "Times New Roman", serif; font-style: italic; line-height: 1; }
#toolbar .supsub sup, #toolbar .supsub sub { font-size: 9px; font-style: normal; }
#toolbar .glyph { font-size: 16px; line-height: 1; }
#toolbar .glyph.serif { font-family: "Times New Roman", "Cambria Math", serif; font-size: 18px; font-style: italic; }

/* ---------- Attachments ---------- */
.item.file { min-width: 200px; }
.fcard {
  display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid #d9d0bf; border-radius: 10px; padding: 8px 8px 8px 8px;
  box-shadow: 0 1px 3px rgba(60,50,30,.1); cursor: move; user-select: none;
}
.item.file:hover .fcard { border-color: #b9ccc9; }
.ficon { width: 38px; height: 46px; flex: none; border-radius: 4px 12px 4px 4px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; position: relative; box-shadow: inset 0 -2px 0 rgba(0,0,0,.12); }
.ficon::after { content: ""; position: absolute; top: 0; right: 0; width: 12px; height: 12px; background: rgba(255,255,255,.45); border-radius: 0 12px 0 4px; }
.ficon span { color: #fff; font-size: 10.5px; font-weight: 800; letter-spacing: .3px; font-family: "Segoe UI", Arial, sans-serif; }
.finfo { flex: 1; min-width: 0; }
.fname { font-size: 13px; font-weight: 600; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-all; }
.fmeta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.fbtn { width: 30px; height: 30px; flex: none; border: 0; border-radius: 7px; background: transparent; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.fbtn:hover { background: var(--accent-soft); color: var(--accent); }
.fbtn svg { width: 17px; height: 17px; }

/* ---------- Inline table / image resize ---------- */
.obj-rsz {
  position: absolute; z-index: 950; width: 16px; height: 16px; border-radius: 4px; background: #fff; border: 2px solid var(--accent);
  cursor: nwse-resize; box-shadow: 0 1px 4px rgba(0,0,0,.25); touch-action: none;
}
.obj-rsz::after { content: ""; position: absolute; right: 2px; bottom: 2px; width: 6px; height: 6px; border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent); }
#sheet.col-hover .content td, #sheet.col-hover .content th { cursor: col-resize; }
body.col-dragging, body.col-dragging * { cursor: col-resize !important; user-select: none !important; }
.content table.nt { table-layout: auto; }

/* ---------- Math ---------- */
.content .math { cursor: pointer; border-radius: 4px; padding: 0 2px; white-space: nowrap; user-select: all; }
.content .math:hover { background: #e7f0ee; box-shadow: 0 0 0 1px #c3d9d5; }
.content .math[data-display="1"] { display: block; text-align: center; margin: .35em 0; white-space: normal; }
.content .math[data-display="1"] .katex-display { margin: 0; }
.content .math .katex { font-size: 1.12em; }
.modal.eq-modal { width: min(640px, calc(100vw - 32px)); }
.eq-tpl { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.eq-b { min-width: 36px; height: 32px; padding: 0 8px; border: 1px solid var(--line); background: #faf8f3; border-radius: 6px; cursor: pointer; font-family: "Times New Roman", "Cambria Math", serif; font-size: 15px; }
.eq-b:hover { background: var(--accent-soft); border-color: #bcd6d2; }
.eq-src { width: 100%; min-height: 70px; resize: vertical; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-family: Consolas, "D2Coding", monospace; font-size: 14px; outline: none; user-select: text; }
.eq-src:focus { border-color: var(--accent); }
.eq-prev { min-height: 64px; margin: 10px 0; border: 1px dashed #cfc6b5; border-radius: 8px; padding: 6px 10px; display: flex; align-items: center; justify-content: center; overflow-x: auto; background: #fffefa; }
.eq-prev .katex-display { margin: 0; }
.eq-empty { color: #b7ae9f; font-size: 13px; }
.eq-opts { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; font-size: 12.5px; }
.eq-opts label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.eq-ex { color: var(--muted); display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.eq-exb { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 2px 4px; text-decoration: underline; font-size: 12.5px; }
.modal .btns { align-items: center; }

/* ---------- Symbol / emoji picker ---------- */
.pop.picker { width: 352px; padding: 6px; }
.pk-tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line-soft); padding-bottom: 4px; margin-bottom: 4px; }
.pk-tabs::-webkit-scrollbar { display: none; }
.pk-tab { flex: none; border: 0; background: none; padding: 5px 9px; border-radius: 6px; cursor: pointer; font-size: 12px; color: var(--muted); white-space: nowrap; }
.pk-tab:hover { background: #f3efe6; }
.pk-tab.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.pk-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 2px; max-height: 236px; overflow-y: auto; }
.pk-c { height: 36px; border: 0; background: none; border-radius: 6px; cursor: pointer; font-size: 17px; line-height: 1; padding: 0; }
.pk-c:hover { background: var(--accent-soft); }
.picker.sym .pk-c { font-family: "Segoe UI Symbol", "Cambria Math", "Malgun Gothic", sans-serif; }
.picker.emo .pk-c { font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; font-size: 21px; }
.pk-foot { font-size: 11px; color: var(--muted); padding: 6px 4px 2px; border-top: 1px solid var(--line-soft); margin-top: 4px; }
@media (max-width: 760px) {
  .pop.picker { width: calc(100vw - 16px); }
  .pk-grid { grid-template-columns: repeat(8, 1fr); }
  .pk-c { height: 42px; }
  .obj-rsz { width: 24px; height: 24px; }
  .item.image.selected .rsz { width: 20px; height: 20px; }
  .eq-src { font-size: 16px; }
}


/* ---------- Fold side panes ---------- */
body.side-folded { --sw: 38px; }
body.pages-folded { --pw: 38px; }
.ph-acts { display: inline-flex; align-items: center; gap: 2px; }
.tb-icon.fold svg { width: 16px; height: 16px; }
.rail {
  display: none; flex: 1; flex-direction: column; align-items: center; gap: 10px; padding: 10px 0; border: 0; background: transparent;
  cursor: pointer; color: var(--muted); width: 100%; border-left: 3px solid transparent;
}
.rail:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.rail svg { width: 16px; height: 16px; }
.rail-label { writing-mode: vertical-rl; font-size: 12.5px; font-weight: 700; letter-spacing: 1px; white-space: nowrap; overflow: hidden; max-height: 70vh; }
body.side-folded #sidebar > :not(.rail) { display: none; }
body.side-folded #railSide { display: flex; }
body.pages-folded #pagesPane > :not(.rail) { display: none; }
body.pages-folded #railPages { display: flex; }

/* ---------- Links ---------- */
.content a[href] { cursor: pointer; }
.st-path { font-family: Consolas, "D2Coding", monospace; font-size: 12.5px; background: #f6f2ea; border-radius: 6px; padding: 8px 10px; word-break: break-all; user-select: text; }
.st-status { font-size: 13px; }
.st-guide { font-size: 12.5px; color: #5d574e; background: #fff8e6; border: 1px solid #f0dfb0; border-radius: 8px; padding: 8px 10px; }
.st-guide code { font-family: Consolas, monospace; }
.st-btns { flex-wrap: wrap; }

/* ---------- Account pill & Cloud Storage Dialogs ---------- */
#accountBtn {
  height: 30px; max-width: 210px; padding: 0 10px; border-radius: 15px;
  border: 1px solid rgba(255,255,255,.22); background: rgba(255,255,255,.12);
  color: var(--top-ink); display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; font-size: 12px; font-weight: 600; flex: none; white-space: nowrap;
}
#accountBtn:hover { background: rgba(255,255,255,.2); }
#accountBtn .acc-dot { width: 8px; height: 8px; border-radius: 50%; background: #d4cbb8; flex: none; }
#accountBtn.is-drive .acc-dot { background: #5eead4; }
#accountBtn.is-syncing .acc-dot { background: #fde047; animation: nlPulse 1s infinite; }
#accountBtn.is-offline .acc-dot { background: #fbbf24; }
#accountBtn.is-error .acc-dot { background: #fca5a5; }
#accountBtn .acc-avatar { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; flex: none; }
#accountBtn .acc-label { overflow: hidden; text-overflow: ellipsis; }
@keyframes nlPulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

@media (max-width: 760px) {
  #accountBtn { max-width: 120px; padding: 0 8px; }
}

.modal.st-modal { width: min(500px, calc(100vw - 24px)); max-height: 86vh; overflow-y: auto; }
.ob-card { text-align: center; padding: 6px 0 4px; }
.ob-logo { height: 42px; width: auto; max-width: 220px; display: block; margin: 0 auto 12px; object-fit: contain; }
.ob-card h3 { margin: 0 0 8px; font-size: 18px; }
.ob-desc { color: #5d574e; font-size: 13.5px; line-height: 1.55; margin: 0 0 18px; }
.ob-google-btn {
  width: 100%; height: 42px; border-radius: 9px; border: 1px solid #d5cec0;
  background: #fff; color: var(--ink); font-weight: 700; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.ob-google-btn:hover { background: #faf8f3; border-color: var(--accent); }
.ob-local-btn { margin-top: 10px; width: 100%; height: 38px; }
.ob-note { margin: 12px 0 0; font-size: 12px; color: var(--muted); line-height: 1.45; }

.st-sec { border: 1px solid var(--line-soft); border-radius: 10px; padding: 12px; margin-bottom: 12px; background: #fcfaf5; }
.st-sec-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .3px; }
.st-account-bar { display: flex; align-items: center; gap: 10px; }
.st-account-bar img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none; background: #e6dfd1; }
.st-account-info { flex: 1; min-width: 0; }
.st-account-name { font-weight: 700; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-account-email { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.st-folder-list { display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; margin-bottom: 10px; }
.st-folder-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  cursor: pointer; text-align: left;
}
.st-folder-item:hover { border-color: var(--accent); background: #f8fbfa; }
.st-folder-item.active { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.st-folder-badge { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: var(--accent); color: #fff; flex: none; }

.st-create-row { display: flex; gap: 6px; }
.st-create-row input { flex: 1; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; background: #fff; }
.st-cfg-box { margin-top: 12px; padding: 10px; border-radius: 8px; background: #f6f2ea; border: 1px solid var(--line); text-align: left; font-size: 12.5px; }
.st-cfg-box input { width: 100%; height: 32px; margin-top: 4px; margin-bottom: 8px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 12.5px; }

/* ---------- Print / PDF ---------- */
@media print {
  html, body { height: auto; overflow: visible; background: #fff; display: block; }
  #topbar, #toolbar, #sidebar, #pagesPane, #statusbar, #emptyState, .ctx, .pop, #toast, #recBar, #backdrop { display: none !important; }
  #editorPane, #canvasScroll { position: static; overflow: visible; background: #fff; }
  #sheet { zoom: 1 !important; width: var(--print-w) !important; height: var(--print-h) !important; min-width: 0; min-height: 0; background-image: none !important; }
  .item, .item:hover, .item.selected { outline: none !important; }
  .grip, .rsz, .rsz-w, .obj-rsz, .fbtn { display: none !important; }
  #pageTitle { border-bottom-color: #ddd; }
}
