:root {
  --bg: #ffffff;
  --side: #f7f7f5;
  --line: #e9e9e7;
  --text: #37352f;
  --muted: #8b8a86;
  --hover: #efefed;
  --accent: #2f76e6;
  --accent-soft: #e7f0fd;
  --danger: #d9443a;
  --warn: #c98a00;
  --ok: #2e9d5b;
  --radius: 10px;
  --side-w: 300px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191919;
    --side: #202020;
    --line: #2f2f2f;
    --text: #e6e6e4;
    --muted: #9b9a97;
    --hover: #2c2c2c;
    --accent: #5b9bf8;
    --accent-soft: #1f2d42;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--accent); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px;
  padding: 11px 16px; font-weight: 600;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; border-radius: 8px; color: var(--muted);
  text-decoration: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--accent); }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--side); }
.login-card {
  width: 100%; max-width: 420px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px 28px; box-shadow: 0 10px 30px rgba(0,0,0,.06);
}
.login-logo { font-size: 44px; }
.login h1 { font-size: 22px; margin: 10px 0 6px; }
.login-sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; line-height: 1.5; }
.login form { display: flex; flex-direction: column; gap: 10px; }
.login label { font-size: 13px; font-weight: 600; }
.login input {
  border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; font-size: 16px; background: var(--bg);
}
.login input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
#login-code { letter-spacing: 8px; font-size: 22px; text-align: center; font-weight: 700; }
.login-hint { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; }
.dev-badge { background: #fff3cd; color: #8a6100; border-radius: 4px; padding: 1px 6px; font-size: 11px; font-weight: 700; }
.dev-code { color: var(--text); letter-spacing: 2px; }
.login-features { list-style: none; padding: 18px 0 0; margin: 22px 0 0; border-top: 1px solid var(--line); display: grid; gap: 9px; font-size: 13px; color: var(--muted); }
.login-features i { width: 18px; color: var(--accent); }

/* ---------- shell ---------- */
.shell { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: var(--side-w); flex: none; background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: relative;
}
.side-head { display: flex; align-items: center; gap: 6px; padding: 14px 10px 8px 16px; }
.brand { font-weight: 700; font-size: 16px; flex: 1; }
.sync-badge { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.sync-badge.ok { color: var(--ok); }
.sync-badge.off { color: var(--warn); }
.search {
  margin: 4px 12px 8px; display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; color: var(--muted);
}
.search input { border: 0; outline: 0; background: transparent; padding: 9px 0; flex: 1; min-width: 0; font-size: 15px; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 2px 12px 10px; border-bottom: 1px solid var(--line); }
.nav-item {
  border: 1px solid transparent; background: transparent; border-radius: 999px; padding: 4px 10px;
  font-size: 13px; color: var(--muted); display: inline-flex; gap: 4px; align-items: center;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.list { flex: 1; overflow-y: auto; padding: 6px 8px 90px; }
.list-empty { text-align: center; color: var(--muted); font-size: 14px; padding: 40px 10px; line-height: 1.6; }
.note-item {
  width: 100%; display: flex; gap: 10px; align-items: flex-start; text-align: left;
  border: 0; background: transparent; border-radius: 8px; padding: 10px; margin-bottom: 2px;
}
.note-item:hover { background: var(--hover); }
.note-item.active { background: var(--accent-soft); }
.ni-icon { font-size: 18px; line-height: 22px; }
.ni-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ni-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ni-preview { font-size: 12.5px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.45; }
.ni-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.ni-pin { color: var(--accent); font-size: 10px; }
.ni-dirty { color: var(--warn); font-size: 6px; }
.fab {
  position: absolute; left: 12px; right: 12px; bottom: calc(14px + var(--safe-b));
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; background: var(--accent); color: #fff; border-radius: 12px; padding: 13px; font-weight: 700;
  box-shadow: 0 6px 16px rgba(47,118,230,.3);
}

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.empty { margin: auto; text-align: center; padding: 30px 20px; max-width: 720px; }
.empty-icon { font-size: 48px; }
.empty h2 { margin: 10px 0 6px; font-size: 20px; }
.empty p { color: var(--muted); font-size: 14px; margin: 0 0 26px; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.template-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  border: 1px solid var(--line); background: var(--bg); border-radius: var(--radius); padding: 14px;
  transition: transform .12s, box-shadow .12s;
}
.template-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.07); border-color: var(--accent); }
.template-card small { color: var(--muted); font-size: 12px; }
.t-icon { font-size: 26px; }

.note-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.note-bar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid transparent; }
.save-state { font-size: 12px; color: var(--muted); flex: 1; }
.save-state.busy { color: var(--warn); }
.note-actions { display: flex; gap: 2px; }
.trash-banner {
  background: #fdecea; color: #8c2a23; font-size: 14px; padding: 10px 16px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.note-scroll { flex: 1; overflow-y: auto; padding: 10px 0 120px; -webkit-overflow-scrolling: touch; }
.note-head, #editor { max-width: 760px; margin: 0 auto; padding: 0 56px; }
.note-icon { font-size: 44px; border: 0; background: transparent; border-radius: 10px; padding: 2px 6px; margin-left: -6px; }
.note-icon:hover { background: var(--hover); }
#note-title {
  width: 100%; border: 0; outline: 0; resize: none; background: transparent; overflow: hidden;
  font-size: 32px; font-weight: 700; line-height: 1.25; padding: 6px 0; display: block;
}
#note-title::placeholder { color: #c5c4c0; }
.note-meta { font-size: 12px; color: var(--muted); padding: 2px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.quickbar { display: none; }
.mobile-only { display: none !important; }

/* ---------- editor.js overrides ---------- */
.codex-editor { font-size: 16px; line-height: 1.65; }
.ce-block__content, .ce-toolbar__content { max-width: none; }
.ce-paragraph[data-placeholder]:empty::before { color: #c5c4c0; }
.ce-header { padding: .5em 0 .15em; margin: 0; }
h1.ce-header { font-size: 1.75em; } h2.ce-header { font-size: 1.4em; } h3.ce-header { font-size: 1.15em; }
.cdx-quote__text { min-height: 40px; border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; }
.image-tool__image-picture { border-radius: 8px; max-height: 80vh; object-fit: contain; }
.tc-table { font-size: 14px; }
.tc-wrap { --color-border: var(--line); }
.cdx-input, .ce-code__textarea { background: var(--side) !important; color: var(--text) !important; border-color: var(--line) !important; }
.ce-toolbar__plus, .ce-toolbar__settings-btn { color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .ce-popover, .ce-inline-toolbar, .ce-conversion-toolbar, .ce-settings, .tc-popover {
    --color-background: #252525; --color-text-primary: #e6e6e4; --color-border: #333; --color-background-item-hover: #333;
    background: #252525; color: #e6e6e4;
  }
  .ce-toolbar__plus:hover, .ce-toolbar__settings-btn:hover, .ce-inline-tool:hover { background: #333; }
  .ce-block--selected .ce-block__content { background: #22324a; }
  .cdx-marker { background: rgba(245, 235, 111, .35); color: inherit; }
  .trash-banner { background: #3a1f1d; color: #f2b8b2; }
}

/* ---------- attachment ---------- */
.attach-block { margin: 8px 0; }
.attach-picker {
  display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer;
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; color: var(--muted);
}
.attach-picker i { font-size: 26px; color: var(--accent); }
.attach-picker span { font-weight: 600; color: var(--text); }
.attach-picker small { font-size: 12px; }
.attach-picker.drag, .attach-picker:hover { border-color: var(--accent); background: var(--accent-soft); }
.attach-card {
  display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 10px 12px 14px; background: var(--side);
}
.attach-icon { font-size: 26px; color: var(--accent); width: 28px; text-align: center; }
.attach-info { flex: 1; min-width: 0; }
.attach-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.attach-media { width: 100%; margin-top: 8px; border-radius: 8px; max-height: 70vh; background: #000; }
audio.attach-media { background: transparent; }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 7px; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .2s; }

/* ---------- modal / toast ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15,15,15,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s;
}
.modal {
  background: var(--bg); border-radius: 14px; padding: 20px; width: 100%; max-width: 380px;
  max-height: 85vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal.wide { max-width: 640px; }
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.menu-list { display: flex; flex-direction: column; gap: 4px; }
.menu-btn {
  display: flex; align-items: center; gap: 10px; border: 0; background: transparent; text-align: left;
  padding: 11px 10px; border-radius: 8px; font-size: 15px;
}
.menu-btn i { width: 18px; color: var(--muted); }
.menu-btn:hover { background: var(--hover); }
.menu-btn.danger, .menu-btn.danger i { color: var(--danger); }
.menu-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; font-size: 15px; }
.menu-row select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--bg); }
.account { padding: 6px 10px 12px; font-weight: 600; word-break: break-all; }
.storage { padding: 4px 10px 12px; font-size: 13px; }
.storage-row { display: flex; justify-content: space-between; }
.storage small { color: var(--muted); display: block; margin-top: 6px; }
.tip { font-size: 13px; color: var(--muted); padding: 2px 10px; margin: 4px 0; line-height: 1.5; }
.icon-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.icon-choice { font-size: 24px; border: 0; background: transparent; border-radius: 8px; padding: 6px 0; }
.icon-choice:hover { background: var(--hover); }
#toasts {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + var(--safe-b)); z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: #2b2b2b; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: up .2s; transition: opacity .3s, transform .3s;
}
.toast.error { background: var(--danger); }
.toast.warn { background: #8a6100; }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes fade { from { opacity: 0 } }
@keyframes up { from { opacity: 0; transform: translateY(8px) } }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .sidebar { width: 100%; border-right: 0; }
  .main { display: none; }
  body.show-editor .sidebar { display: none; }
  body.show-editor .main { display: flex; }
  .mobile-only { display: inline-flex !important; }
  .note-head, #editor { padding: 0 18px; }
  #note-title { font-size: 26px; }
  .note-icon { font-size: 36px; }
  .note-bar { position: sticky; top: 0; background: var(--bg); border-bottom-color: var(--line); padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
  .note-actions #img-btn, .note-actions #file-btn { display: none; }
  .note-scroll { padding-bottom: calc(90px + var(--safe-b)); }
  .quickbar {
    display: flex !important; justify-content: space-around; position: sticky; bottom: 0;
    background: var(--bg); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-b));
  }
  .quickbar.hidden { display: none !important; }
  .quickbar button { border: 0; background: transparent; color: var(--muted); font-size: 18px; padding: 8px 12px; border-radius: 8px; }
  .quickbar button:active { background: var(--hover); color: var(--accent); }
  .ce-toolbar__actions { right: auto; left: -4px; }
  .ce-toolbar__plus { display: none; }
  .codex-editor--narrow .ce-toolbox .ce-popover { right: auto; left: 0; }
  .template-grid { grid-template-columns: repeat(2, 1fr); }
  /* 표: 휴대폰에서 글자 쪼개짐 방지 → 가로 스크롤 */
  .tc-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tc-table { width: max-content; min-width: 100%; }
  .tc-row { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(92px, 1fr); }
  .tc-cell { word-break: keep-all; overflow-wrap: anywhere; }
  .empty { padding-top: 40px; }
  .side-head { padding-top: calc(14px + env(safe-area-inset-top, 0px)); }
}
