/* JENJEN Note — 젠젠 CI(검정·흰색, 굵은 장체 로고) + 회사 홈페이지 색(먹·종이·포인트 파랑) */
:root {
  --ink: #0e0e10;
  --ink-2: #1b1b1f;
  --paper: #fafaf8;
  --paper-2: #f1f1ee;
  --line: rgba(14, 14, 16, 0.12);
  --muted: #6b6c75;
  --side-muted: #8e8f99;
  --point: #2c46ff;
  --bg: var(--paper);
  --fg: var(--ink);
  --sel-bg: var(--ink);
  --sel-fg: var(--paper);
  --wide: 'Archivo', 'Pretendard Variable', Pretendard, sans-serif;
  --kr: 'Pretendard Variable', Pretendard, 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  --mono: 'Space Mono', 'Pretendard Variable', Pretendard, 'Malgun Gothic', monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --fg: #ececea;
    --paper-2: #1a1a1e;
    --line: rgba(250, 250, 248, 0.12);
    --muted: #9a9ba6;
    --sel-bg: var(--paper);
    --sel-fg: var(--ink);
  }
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--fg);
  font: 15px/1.65 var(--kr);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; border-radius: 0; padding: 4px 10px; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--point); outline-offset: 2px; }
button.ghost { color: var(--muted); font-size: 13px; }
button.ghost:hover { color: var(--fg); }
button.small { font-size: 12px; padding: 2px 8px; }
button.icon { width: 32px; height: 32px; padding: 0; font-size: 16px; line-height: 32px; }
button.new {
  background: var(--paper); color: var(--ink);
  font-family: var(--wide); font-stretch: 75%; font-weight: 800;
  letter-spacing: 0.02em; text-transform: uppercase; padding: 9px 12px;
}
button.new:hover { background: #fff; }
ul { list-style: none; margin: 0; padding: 0; }

.brand { font-family: var(--wide); font-stretch: 72%; font-weight: 600; font-size: 22px; letter-spacing: 0.005em; line-height: 1; }
.brand b { font-weight: 850; letter-spacing: -0.005em; }

#app { display: grid; grid-template-columns: 228px 310px 1fr; height: 100dvh; }

/* 사이드바 = 검정 명함 */
#sidebar {
  background: var(--ink); color: var(--paper);
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
  padding: max(16px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
.side-head { display: flex; align-items: center; gap: 2px; padding: 2px 4px 10px; border-bottom: 1px solid rgba(250, 250, 248, 0.14); }
.side-head .brand { flex: 1; }
.side-head button { color: var(--side-muted); }
.side-head button:hover { color: var(--paper); }
#btn-new-note { margin: 4px 0 8px; }
.side-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 600; color: var(--side-muted); padding: 0 4px;
}
.side-label button { color: var(--side-muted); }
.side-label button:hover { color: var(--paper); }
#books { overflow: auto; flex: 1; }
#books li, #trash-link li {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 4px 6px 10px; cursor: pointer; color: #cfcfd4;
  border-left: 2px solid transparent;
}
#books li:hover, #trash-link li:hover { color: var(--paper); background: var(--ink-2); }
#books li.on, #trash-link li.on { color: var(--paper); background: var(--ink-2); border-left-color: var(--point); font-weight: 600; }
#trash-link { border-top: 1px solid rgba(250, 250, 248, 0.14); padding-top: 8px; }
.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-family: var(--mono); font-size: 11px; color: var(--side-muted); }
#books .more { width: 26px; height: 26px; line-height: 26px; padding: 0; color: var(--side-muted); opacity: 0; }
#books li:hover .more, #books li.on .more { opacity: 1; }
#sync-status { font-family: var(--mono); font-size: 10.5px; color: var(--side-muted); padding: 2px 4px; line-height: 1.5; }
#sync-status.err { color: #ff8a73; }

/* 노트 목록 = 흰 명함 */
#list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.list-head {
  display: flex; align-items: center; gap: 6px;
  padding: max(16px, env(safe-area-inset-top)) 16px 8px;
}
.list-head h2 {
  flex: 1; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 20px; font-weight: 800; letter-spacing: -0.02em;
}
#search {
  margin: 0 16px 10px; padding: 8px 10px; font-size: 14px;
  border: 0; border-bottom: 1.5px solid var(--fg); border-radius: 0; background: transparent;
}
#search:focus { outline: none; border-bottom-color: var(--point); }
#notes { overflow: auto; flex: 1; }
#notes li { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
#notes li:hover { background: var(--paper-2); }
#notes li.on { background: var(--sel-bg); color: var(--sel-fg); }
/* 꾹 눌러 여러 개 고르기 */
#notes li { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.selecting #notes li { position: relative; padding-left: 46px; }
.selecting #notes li::before {
  content: ''; position: absolute; left: 15px; top: 50%; width: 18px; height: 18px; margin-top: -11px;
  border: 2px solid var(--muted); border-radius: 50%;
}
.selecting #notes li.sel { background: var(--paper-2); }
.selecting #notes li.sel::before { background: var(--point); border-color: var(--point); }
.selecting #notes li.sel::after {
  content: '✓'; position: absolute; left: 15px; top: 50%; width: 22px; margin-top: -11px;
  line-height: 22px; text-align: center; color: #fff; font-size: 13px; font-weight: 800;
}
.sel-bar h2 { font-size: 17px; }
.sel-go { padding: 7px 12px; border-radius: 6px; background: var(--point); color: #fff; font-size: 13px; font-weight: 700; }
.sel-go:disabled { opacity: 0.4; }
#notes li.on .s, #notes li.on .d { color: inherit; opacity: 0.68; }
#notes .t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#notes .s {
  font-size: 13px; color: var(--muted); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: keep-all; overflow-wrap: anywhere;
}
#notes .d { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 4px; }
#notes .none { color: var(--muted); cursor: default; border: 0; }
#notes .none:hover { background: none; }

/* 편집기 = 종이 */
#editor-pane { display: flex; flex-direction: column; min-width: 0; position: relative; background: var(--bg); }
.ed-head {
  display: flex; align-items: center; gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 28px 6px; color: var(--muted); font-size: 13px;
}
#note-book {
  border: 1px solid var(--line); border-radius: 0; background: var(--bg);
  padding: 4px 6px; font-size: 13px; max-width: 45%;
}
#saved { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: var(--mono); font-size: 11px; }
.ed-head button { white-space: nowrap; flex-shrink: 0; }
#btn-restore { color: var(--point); font-weight: 700; }
#note-area { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#title {
  border: 0; outline: none; background: none;
  font-size: 30px; font-weight: 800; letter-spacing: -0.03em; padding: 8px 40px 6px;
}
#editor {
  flex: 1; overflow: auto; outline: none;
  padding: 6px 40px 40vh; font-size: 16px; line-height: 1.75;
  word-break: keep-all; overflow-wrap: anywhere;
}
#editor > div { min-height: 1.75em; }
#editor hr { border: 0; border-top: 2px solid var(--fg); margin: 14px 0; }
/* 그림: 칸 너비에 맞추고, 누르면 크게 보기 */
#editor img { display: block; max-width: 100%; max-height: 70vh; width: auto; height: auto; margin: 6px 0; border: 1px solid var(--line); cursor: zoom-in; }
#editor img:not([src]) { width: 120px; height: 72px; background: var(--line); }
#img-view { position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.94); display: flex; flex-direction: column; }
#img-view[hidden] { display: none; }
#img-view-bar { display: flex; justify-content: space-between; align-items: center; padding: max(10px, env(safe-area-inset-top)) 12px 8px; }
#img-view-bar button { color: #fff; font-size: 15px; padding: 8px 10px; }
#img-view-bar button[hidden] { visibility: hidden; display: block; }
#img-view-body { flex: 1; min-height: 0; overflow: auto; display: flex; }
#img-view-body img { margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; }
#img-view-body img.zoom { max-width: none; max-height: none; cursor: zoom-out; }
/* 체크박스: 에버노트처럼 작게(15px)·얇은 회색 테두리·둥근 모서리, 체크하면 채우고 흰 체크 */
#editor .todo { position: relative; padding-left: 25px; }
#editor .todo::before {
  content: ""; position: absolute; left: 2px; top: calc((1.75em - 15px) / 2);
  box-sizing: border-box; width: 15px; height: 15px;
  border: 1.5px solid var(--side-muted); border-radius: 3px; background: var(--bg); cursor: pointer;
  transition: background .12s, border-color .12s;
}
#editor .todo:hover::before { border-color: var(--fg); }
#editor .todo[data-checked]::before { background: var(--fg); border-color: var(--fg); }
#editor .todo[data-checked]::after {
  content: ""; position: absolute; left: 7.5px; top: calc((1.75em - 15px) / 2 + 2.5px);
  box-sizing: border-box; width: 4px; height: 8px;
  border: solid var(--bg); border-width: 0 1.8px 1.8px 0; transform: rotate(45deg); pointer-events: none;
}
#editor .todo[data-checked] { color: var(--muted); text-decoration: line-through; }
#editor-pane.readonly #title, #editor-pane.readonly #editor { color: var(--muted); }
#empty {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center; color: var(--muted);
}
#editor-pane.blank #note-area, #editor-pane.blank .ed-head > :not(#btn-back) { visibility: hidden; }
#editor-pane.blank #empty { display: flex; }

/* 알림 띠 */
#toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: var(--paper); padding: 10px 12px 10px 16px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); z-index: 20; max-width: calc(100vw - 32px);
}
#toast-undo { color: #8c9bff; font-weight: 700; padding: 2px 6px; }

/* 잠금 화면 */
#lock {
  position: fixed; inset: 0; z-index: 30; background: var(--ink); color: var(--paper);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#lock-form { display: flex; flex-direction: column; align-items: center; gap: 12px; width: min(300px, 100%); }
#lock .brand.big { font-size: 40px; margin-bottom: 8px; }
#lock p { margin: 0; color: var(--side-muted); font-size: 14px; min-height: 1.4em; text-align: center; }
#lock-pin {
  width: 100%; text-align: center; font-size: 26px; letter-spacing: 0.4em;
  background: transparent; border: 0; border-bottom: 2px solid var(--paper); padding: 6px; color: var(--paper);
}
#lock-pin:focus { outline: none; border-bottom-color: var(--point); }
/* 잠금 번호: 비밀번호 칸이 아니라 글자칸 + 점으로 가리기(자동완성 안 뜨게) */
.pin-mask { -webkit-text-security: disc; text-security: disc; }
.pin-mask::placeholder { -webkit-text-security: none; }
#lock .new { width: 100%; }

/* 설정 창 */
dialog {
  border: 0; border-top: 6px solid var(--ink); padding: 22px 24px; border-radius: 0;
  background: var(--bg); color: var(--fg); width: min(400px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(14, 14, 16, 0.55); }
dialog h3 { margin: 0 0 14px; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
dialog .hint { margin: -4px 0 14px; font-size: 12.5px; color: var(--muted); line-height: 1.55; word-break: keep-all; }
dialog label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 14px; }
dialog small { font-weight: 400; color: var(--muted); margin-left: 4px; }
dialog input {
  display: block; width: 100%; margin-top: 4px; padding: 8px 2px; font-size: 16px;
  border: 0; border-bottom: 1.5px solid var(--fg); border-radius: 0; background: transparent;
}
dialog input:focus { outline: none; border-bottom-color: var(--point); }
#set-msg { color: var(--point); margin-top: 0; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 6px 0 0; padding: 0; }
dialog menu .new { background: var(--ink); color: var(--paper); padding: 8px 22px; }
dialog menu .new:hover { background: var(--ink-2); }
dialog menu .new:disabled { opacity: 0.5; }
@media (prefers-color-scheme: dark) {
  dialog { border-top-color: var(--paper); }
  dialog menu .new { background: var(--paper); color: var(--ink); }
}

/* 첫 실행·설치 안내, 폰 연결 QR */
#set-msg, #pair-msg { color: var(--point); margin-top: 0; }
dialog .steps { list-style: none; margin: 0 0 16px; padding: 0; }
dialog .steps li { padding: 12px 0; border-top: 1px solid var(--paper-2); font-size: 14px; line-height: 1.55; word-break: keep-all; }
dialog .steps li .state { margin-left: 6px; font-size: 13px; font-weight: 700; color: var(--point); }
dialog .steps li .do { margin-top: 6px; color: var(--fg); }
dialog .steps li.done .do { display: none; }
dialog .steps .new, dialog .callout .new, #pair-confirm .new, #dlg-join .new { background: var(--ink); color: var(--paper); padding: 10px 16px; margin: 8px 0 4px; display: block; width: 100%; font-weight: 700; }
dialog .callout { background: var(--paper-2); padding: 12px 14px; margin: 0 0 14px; font-size: 13.5px; line-height: 1.55; word-break: keep-all; }
dialog .callout small { display: block; margin: 0; }
#pair-svg { background: #fff; padding: 10px; margin: 0 auto 12px; width: min(280px, 100%); }
#pair-svg svg { display: block; width: 100%; height: auto; }
@media (prefers-color-scheme: dark) {
  dialog .steps .new, dialog .callout .new, #pair-confirm .new, #dlg-join .new { background: var(--paper); color: var(--ink); }
}

.mobile-only { display: none; }

/* 폰: 한 화면에 한 칸씩 */
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #sidebar, #list, #editor-pane { display: none; border: 0; }
  #app[data-view="books"] #sidebar,
  #app[data-view="list"] #list,
  #app[data-view="editor"] #editor-pane { display: flex; }
  .mobile-only { display: inline-block; }
  #btn-new-note { display: none; }
  #books li, #trash-link li { padding: 11px 4px 11px 12px; font-size: 16px; }
  #books .more { opacity: 1; }
  #title { padding: 6px 18px 4px; font-size: 25px; }
  #editor { padding: 4px 18px 40vh; }
  .ed-head { padding-left: 8px; padding-right: 12px; gap: 6px; }
  #note-book { max-width: 36%; min-width: 0; flex-shrink: 1; }
  #search { font-size: 16px; }
}
/* 폰 연결: 두 화면에서 대조할 숫자 4자리 */
.code { font: 700 44px/1.1 'Space Mono', ui-monospace, monospace; letter-spacing: .25em; text-align: center; margin: 8px 0 14px; }
.code-in { display: block; width: 100%; font-size: 34px; padding: 8px 4px; border: 0; border-bottom: 2px solid var(--fg); border-radius: 0; background: transparent; color: inherit; }
#pair-confirm .ghost { width: 100%; margin-top: 6px; }

/* PC 첫 연결: 안내창 안 암호 칸 */
#dlg-setup .setup-pc { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
#dlg-setup .setup-pc input { flex: 1 1 200px; font: inherit; font-size: 16px; padding: 10px 12px; border: 1.5px solid var(--fg); border-radius: 0; background: var(--bg); color: var(--fg); }
#dlg-setup .setup-pc button { font-size: 16px; padding: 10px 22px; }
#dlg-setup .setup-pc-msg { flex-basis: 100%; margin: 4px 0 0; font-size: 15px; font-weight: 600; min-height: 1.4em; }
#dlg-setup .setup-pc-msg.ok { color: #128a3e; }
#dlg-setup .setup-pc-msg.bad { color: #c62828; }
