/* =========================================================
   필기 — 공부 노트
   종이가 주인공. 도구는 얇고 조용하게, 고른 도구만 또렷하게.
   ========================================================= */
:root {
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --bar-h: 54px;
  --radius: 14px;
  --radius-sm: 10px;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e6e9ee;
  --ink: #1b2130;
  --ink-2: #4a5263;
  --ink-3: #737b8c;
  --line: #e3e6eb;
  --line-2: #d2d6de;
  --accent: #3b5bdb;
  --accent-ink: #2f4bc0;
  --accent-soft: #e9eefe;
  --on-accent: #ffffff;
  --danger: #d92d20;
  --danger-soft: #fdecea;
  --ok: #12825a;
  --warn: #b7791f;
  --desk: #e7e9ed;
  --shadow-1: 0 1px 2px rgba(18, 24, 38, 0.06), 0 1px 1px rgba(18, 24, 38, 0.04);
  --shadow-2: 0 10px 30px -12px rgba(18, 24, 38, 0.28), 0 2px 6px rgba(18, 24, 38, 0.06);
  --shadow-3: 0 24px 60px -20px rgba(18, 24, 38, 0.38), 0 4px 14px rgba(18, 24, 38, 0.08);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #15171b;
  --surface: #1e2126;
  --surface-2: #262a30;
  --surface-3: #30353c;
  --ink: #eceef2;
  --ink-2: #b9bfca;
  --ink-3: #8c93a0;
  --line: #2c3036;
  --line-2: #3a3f47;
  --accent: #7b96ff;
  --accent-ink: #9db0ff;
  --accent-soft: #252d4a;
  --on-accent: #0f1430;
  --danger: #ff6b5f;
  --danger-soft: #3a2422;
  --desk: #111316;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 10px 30px -12px rgba(0, 0, 0, 0.7), 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-3: 0 24px 60px -20px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; opacity: 0.38; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; }
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

/* ---------- 공통 단추 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 999px; font-weight: 600; font-size: 14.5px;
  transition: background-color 160ms var(--ease), transform 120ms var(--ease), box-shadow 160ms var(--ease);
  white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn--primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 1px 0 rgba(255,255,255,.15) inset, var(--shadow-1); }
.btn--primary:hover:not(:disabled) { background: var(--accent-ink); }
:root[data-theme="dark"] .btn--primary:hover:not(:disabled) { background: #92a8ff; }
.btn--ghost { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--block { width: 100%; height: 46px; font-size: 15.5px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: inline-grid; place-items: center; color: var(--ink-2);
  transition: background-color 140ms var(--ease), color 140ms var(--ease), transform 120ms var(--ease);
  flex: none;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.icon-btn:active:not(:disabled) { transform: scale(0.94); }
.icon-btn--sm { width: 32px; height: 32px; border-radius: 9px; }
.icon-btn--sm svg { width: 18px; height: 18px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 32px; padding: 0 12px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; color: var(--ink-2); background: var(--surface-2);
  transition: background-color 140ms var(--ease), color 140ms var(--ease);
  white-space: nowrap;
}
.chip svg { width: 16px; height: 16px; }
.chip:hover { color: var(--ink); }
.chip.is-on { background: var(--accent-soft); color: var(--accent-ink); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; flex: none; }
.seg__btn { height: 28px; padding: 0 11px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink-3); white-space: nowrap; transition: background-color 140ms var(--ease), color 140ms var(--ease); }
.seg__btn:hover { color: var(--ink); }
.seg__btn.is-on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
:root[data-theme="dark"] .seg__btn.is-on { background: var(--surface-3); }
.seg--block { display: flex; width: 100%; }
.seg--block .seg__btn { flex: 1; height: 36px; font-size: 14.5px; }

/* ---------- 입력 칸 ---------- */
.field { display: grid; gap: 6px; }
.field__label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field__input {
  height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface);
  font-size: 15.5px; transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease); width: 100%;
}
select.field__input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 20px) 19px, calc(100% - 15px) 19px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.field__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- 대화상자 ---------- */
.dlg {
  border: 0; padding: 22px; border-radius: 20px; background: var(--surface); color: var(--ink);
  width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow-3); max-height: calc(100dvh - 48px); overflow: auto;
}
.dlg--wide { width: min(560px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(14, 18, 28, 0.38); backdrop-filter: blur(2px); }
.dlg[open] { animation: dlg-in 220ms var(--ease); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.dlg__title { margin: 0 0 14px; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.dlg__body { color: var(--ink-2); margin-bottom: 14px; }
.dlg__form { display: grid; gap: 14px; }
.dlg__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.keys { border-collapse: collapse; width: 100%; font-size: 14px; }
.keys th { text-align: left; font-weight: 600; color: var(--ink); padding: 7px 12px 7px 0; white-space: nowrap; vertical-align: top; }
.keys td { color: var(--ink-2); padding: 7px 0; }
.keys tr + tr { border-top: 1px solid var(--line); }

.swatch-pick { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch-pick__item { width: 34px; height: 34px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); transition: transform 140ms var(--ease); }
.swatch-pick__item.is-on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }
.paper-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 10px; }
.paper-pick__item { display: grid; gap: 6px; justify-items: center; padding: 8px 4px 6px; border-radius: 12px; font-size: 12.5px; color: var(--ink-2); font-weight: 600; transition: background-color 140ms; }
.paper-pick__item:hover { background: var(--surface-2); }
.paper-pick__item.is-on { background: var(--accent-soft); color: var(--accent-ink); }
.paper-pick__img { width: 52px; height: 68px; border-radius: 4px; background-color: #fff; box-shadow: 0 0 0 1px var(--line-2), 0 2px 6px rgba(0,0,0,.06); }
.paper-thumb--ruled { background-image: linear-gradient(90deg, transparent 9px, #efb7b2 9px, #efb7b2 10px, transparent 10px), repeating-linear-gradient(transparent 0 7px, #cdd7e6 7px 8px); background-position: 0 0, 0 12px; }
.paper-thumb--narrow { background-image: linear-gradient(90deg, transparent 9px, #efb7b2 9px, #efb7b2 10px, transparent 10px), repeating-linear-gradient(transparent 0 5px, #cdd7e6 5px 6px); background-position: 0 0, 0 12px; }
.paper-thumb--grid { background-image: linear-gradient(#e2e7ef 1px, transparent 1px), linear-gradient(90deg, #e2e7ef 1px, transparent 1px); background-size: 6px 6px; }
.paper-thumb--dot { background-image: radial-gradient(#b5bfce 0.8px, transparent 0.9px); background-size: 6px 6px; }
.paper-thumb--cornell { background-image: linear-gradient(90deg, transparent 15px, #c4ccd9 15px, #c4ccd9 16px, transparent 16px), linear-gradient(transparent 52px, #c4ccd9 52px, #c4ccd9 53px, transparent 53px), linear-gradient(transparent 9px, #c4ccd9 9px, #c4ccd9 10px, transparent 10px); }

/* ---------- 메뉴 ---------- */
.menu {
  position: fixed; z-index: 60; min-width: 210px; padding: 6px; background: var(--surface); border-radius: 14px;
  box-shadow: var(--shadow-3), 0 0 0 1px var(--line); animation: pop 160ms var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
.menu__item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 9px; text-align: left; font-size: 14.5px; color: var(--ink); }
.menu__item:hover:not(:disabled), .menu__item:focus-visible { background: var(--surface-2); outline: none; }
.menu__item:disabled { opacity: 1; color: var(--ink-3); font-weight: 600; font-size: 13px; }
.menu__item.is-danger { color: var(--danger); }
.menu__icon { color: var(--ink-3); }
.menu__icon svg { width: 18px; height: 18px; }
.menu__item.is-danger .menu__icon { color: var(--danger); }
.menu__hint { margin-left: auto; font: 500 12px var(--font); color: var(--ink-3); }
.menu__sep { height: 1px; margin: 5px 6px; background: var(--line); }

.color-pop { min-width: 0; padding: 12px; }
.color-pop__grid { display: grid; grid-template-columns: repeat(6, 32px); gap: 8px; }
.color-pop__custom { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.color-pop__custom input { width: 44px; height: 30px; border: 0; padding: 0; background: none; cursor: pointer; }

/* ---------- 알림 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--sab)); z-index: 80; transform: translate(-50%, 20px);
  display: flex; align-items: center; gap: 12px; max-width: min(560px, calc(100vw - 32px));
  padding: 11px 12px 11px 18px; border-radius: 14px; background: #1f2430; color: #f1f3f7; font-size: 14.5px;
  box-shadow: var(--shadow-3); opacity: 0; pointer-events: none; transition: opacity 200ms var(--ease), transform 260ms var(--ease);
}
:root[data-theme="dark"] .toast { background: #eceef2; color: #1b2130; }
.toast.is-on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast__btn { flex: none; height: 32px; padding: 0 12px; border-radius: 9px; background: rgba(255,255,255,.12); color: #9db0ff; font-weight: 700; font-size: 14px; }
:root[data-theme="dark"] .toast__btn { background: rgba(0,0,0,.08); color: var(--accent-ink); }
.toast > span { padding-right: 6px; }

/* ---------- 시작 · 로그인 ---------- */
.splash { flex: 1; display: grid; place-items: center; }
.splash .gate__mark { animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.5; transform: scale(0.96); } }
.gate {
  flex: 1; display: grid; place-items: center; padding: 24px; overflow: auto;
  background:
    radial-gradient(circle at 1px 1px, var(--line-2) 1px, transparent 1.2px) 0 0 / 22px 22px,
    var(--bg);
}
.gate__card { width: min(400px, 100%); background: var(--surface); border-radius: 24px; padding: 30px 26px 24px; box-shadow: var(--shadow-3), 0 0 0 1px var(--line); display: grid; gap: 18px; }
.gate__brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.gate__mark { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-weight: 800; font-size: 19px; box-shadow: var(--shadow-1); }
.gate__lead { margin: -8px 0 0; color: var(--ink-2); }
.gate__form { display: grid; gap: 14px; }
.gate__err { margin: 0; min-height: 1.4em; color: var(--danger); font-size: 14px; }
.gate__err:empty { min-height: 0; margin: -7px 0; }
.gate__note { margin: 0; font-size: 13px; color: var(--ink-3); }

/* =========================================================
   첫 화면 (노트 목록)
   ========================================================= */
.lib { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.lib-bar {
  display: flex; align-items: center; gap: 16px; padding: calc(10px + var(--sat)) calc(18px + var(--sar)) 10px calc(18px + var(--sal));
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.lib-brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 18px; letter-spacing: -0.02em; min-width: 0; }
.lib-brand__mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); }
.lib-brand__mark svg { width: 20px; height: 20px; }
.sync-pill { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-3); font-size: 12px; font-weight: 600; letter-spacing: 0; white-space: nowrap; }
.sync-pill__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.sync-pill.is-ok .sync-pill__dot { background: var(--ok); }
.sync-pill.is-syncing .sync-pill__dot { background: var(--accent); animation: breathe 1s infinite; }
.sync-pill.is-offline .sync-pill__dot, .sync-pill.is-error .sync-pill__dot, .sync-pill.is-auth .sync-pill__dot { background: var(--warn); }
.lib-search { flex: 1; max-width: 420px; margin-left: auto; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 12px; background: var(--surface-2); color: var(--ink-3); }
.lib-search svg { width: 18px; height: 18px; }
.lib-search input { flex: 1; min-width: 0; border: 0; background: none; height: 100%; font-size: 15px; color: var(--ink); }
.lib-search input:focus { outline: none; }
.lib-search:focus-within { box-shadow: 0 0 0 2px var(--accent); }
.lib-bar__right { display: flex; align-items: center; gap: 6px; }
.acct { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px 0 4px; border-radius: 999px; transition: background-color 140ms; }
.acct:hover { background: var(--surface-2); }
.acct__avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: 14px; }
.acct__name { font-weight: 600; font-size: 14px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.lib-body { flex: 1; display: flex; min-height: 0; }
.lib-side { width: 232px; flex: none; padding: 18px 12px calc(18px + var(--sab)) calc(12px + var(--sal)); border-right: 1px solid var(--line); overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.lib-side__title { font-size: 12px; font-weight: 700; color: var(--ink-3); padding: 4px 10px 8px; letter-spacing: 0.02em; }
.subj { position: relative; display: flex; align-items: center; gap: 8px; width: 100%; height: 40px; padding: 0 8px 0 12px; border-radius: 10px; text-align: left; font-size: 14.5px; font-weight: 600; color: var(--ink-2); transition: background-color 140ms var(--ease), color 140ms; }
.subj:hover { background: var(--surface-2); color: var(--ink); }
.subj.is-on { background: var(--accent-soft); color: var(--accent-ink); }
.subj__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subj__count { font-size: 12.5px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.subj.is-on .subj__count { color: inherit; opacity: 0.8; }
.subj__more { display: none; width: 26px; height: 26px; border-radius: 7px; place-items: center; color: var(--ink-3); }
.subj__more svg { width: 16px; height: 16px; }
.subj:hover .subj__more { display: grid; }
.subj:hover .subj__count { display: none; }
.subj--add { color: var(--ink-3); margin-top: 6px; }
.subj--add svg { width: 18px; height: 18px; }

.lib-main { flex: 1; min-width: 0; overflow: auto; padding: 26px calc(28px + var(--sar)) calc(40px + var(--sab)) 28px; }
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.lib-title { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.025em; }
.lib-actions { display: flex; gap: 8px; }

.nb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(164px, 1fr)); gap: 28px 22px; }
.nb { display: grid; gap: 10px; min-width: 0; }
.nb__open { display: block; border-radius: 6px 14px 14px 6px; transition: transform 200ms var(--ease); }
.nb__open:hover { transform: translateY(-3px); }
.nb__open:active { transform: translateY(-1px) scale(0.985); }
.nb-cover {
  position: relative; display: block; aspect-ratio: 3 / 4; border-radius: 6px 14px 14px 6px; overflow: hidden;
  background:
    linear-gradient(160deg, rgba(255,255,255,.16), rgba(255,255,255,0) 45%),
    var(--cover);
  box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 14px 24px -14px rgba(14, 20, 34, 0.55), 0 2px 4px rgba(14, 20, 34, 0.12);
}
.nb-cover__spine { position: absolute; left: 0; top: 0; bottom: 0; width: 12px; background: linear-gradient(90deg, rgba(0,0,0,.22), rgba(0,0,0,.04) 70%, rgba(255,255,255,.12)); }
.nb-cover__label {
  position: absolute; left: 22px; right: 12px; top: 18%; padding: 10px 12px; border-radius: 6px; background: rgba(255,255,255,.94);
  display: grid; gap: 2px; text-align: left; box-shadow: 0 1px 2px rgba(0,0,0,.08); z-index: 1;
}
.nb-cover__subject { font-size: 11px; font-weight: 700; color: var(--cover); letter-spacing: 0.02em; filter: saturate(1.1) brightness(0.85); }
.nb-cover__title { font-size: 14px; font-weight: 700; color: #1b2130; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; word-break: keep-all; overflow-wrap: anywhere; }
.nb-cover__peek { position: absolute; left: 22px; right: 12px; bottom: -30%; width: calc(100% - 34px); height: auto; border-radius: 4px 4px 0 0; box-shadow: 0 -2px 10px rgba(0,0,0,.18); transform: rotate(-2deg); opacity: 0.96; }
.nb__meta { display: flex; align-items: flex-start; gap: 4px; }
.nb__text { flex: 1; min-width: 0; }
.nb__title { margin: 0; font-size: 14.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nb__sub { margin: 1px 0 0; font-size: 12.5px; color: var(--ink-3); }

.empty { grid-column: 1 / -1; display: grid; justify-items: center; text-align: center; gap: 10px; padding: 64px 16px; }
.empty__art { position: relative; width: 120px; height: 96px; margin-bottom: 8px; }
.empty__art span { position: absolute; bottom: 0; width: 64px; height: 84px; border-radius: 4px 10px 10px 4px; box-shadow: var(--shadow-2); }
.empty__art span:nth-child(1) { left: 0; background: #1c7c6c; transform: rotate(-9deg); }
.empty__art span:nth-child(2) { left: 28px; background: #c2410c; transform: rotate(2deg); height: 90px; }
.empty__art span:nth-child(3) { left: 56px; background: #3b5bdb; transform: rotate(10deg); }
.empty__title { margin: 0; font-size: 18px; font-weight: 700; }
.empty__desc { margin: 0 0 8px; max-width: 380px; color: var(--ink-2); }

/* =========================================================
   편집기
   ========================================================= */
.ed { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--desk); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.ed-bar {
  position: relative; z-index: 5; display: flex; align-items: center; gap: 8px; height: calc(var(--bar-h) + var(--sat));
  padding: var(--sat) calc(8px + var(--sar)) 0 calc(8px + var(--sal)); background: var(--surface); border-bottom: 1px solid var(--line);
}
.ed-bar__left, .ed-bar__right { display: flex; align-items: center; gap: 2px; flex: 1 1 0; min-width: 0; }
.ed-bar__right { justify-content: flex-end; }
.ed-bar__tools { display: flex; align-items: center; gap: 2px; flex: none; }
.ed-bar__sep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; }
.ed-title { min-width: 0; max-width: 260px; height: 36px; padding: 0 10px; border-radius: 10px; font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-title:hover { background: var(--surface-2); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; margin: 0 6px; opacity: 0.6; }
.sync-dot.is-ok { background: var(--ok); opacity: 1; }
.sync-dot.is-busy { background: var(--accent); opacity: 1; animation: breathe 1s infinite; }
.sync-dot.is-off, .sync-dot.is-err { background: var(--warn); opacity: 1; }

.tool { position: relative; flex: none; width: 44px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: var(--ink-2); transition: background-color 140ms var(--ease), color 140ms var(--ease), transform 120ms var(--ease); }
.tool:hover { background: var(--surface-2); color: var(--ink); }
.tool:active { transform: scale(0.93); }
.tool.is-on { background: var(--accent-soft); color: var(--accent-ink); }
.tool.is-on::after { content: ""; position: absolute; left: 50%; bottom: 3px; width: 14px; height: 3px; border-radius: 2px; background: currentColor; transform: translateX(-50%); }

.ed-sub {
  position: absolute; z-index: 4; left: 50%; top: calc(var(--bar-h) + var(--sat) + 10px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 10px; max-width: calc(100vw - 20px); overflow-x: auto; scrollbar-width: none;
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px) saturate(1.4); -webkit-backdrop-filter: blur(12px) saturate(1.4);
  border-radius: 16px; box-shadow: var(--shadow-2), 0 0 0 1px var(--line);
}
.ed-sub::-webkit-scrollbar { display: none; }
.ed-sub:empty { display: none; }
.ed-sub__hint { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; padding-right: 4px; }
.ed-sub__hint:empty { display: none; }
.swatches { display: flex; gap: 6px; flex: none; }
.swatch { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; transition: transform 140ms var(--ease); }
.swatch::before { content: ""; width: 22px; height: 22px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.14); transition: transform 160ms var(--ease); }
.swatch:hover::before { transform: scale(1.08); }
.swatch.is-on { box-shadow: 0 0 0 2px var(--c); }
.swatch.is-on::before { transform: scale(0.82); }
.swatch--lg { width: 32px; height: 32px; }
.swatch--lg::before { width: 26px; height: 26px; }
.sizes { display: flex; gap: 2px; flex: none; }
.size { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--ink-2); }
.size:hover { background: var(--surface-2); }
.size.is-on { background: var(--accent-soft); color: var(--accent-ink); }
.size__dot { display: block; border-radius: 50%; background: currentColor; }

.ed-main { flex: 1; display: flex; min-height: 0; position: relative; }
.ed-pages {
  width: 0; flex: none; overflow: hidden; background: var(--surface); border-right: 1px solid var(--line);
  transition: width 240ms var(--ease); display: flex; flex-direction: column;
}
.ed.has-side .ed-pages { width: 176px; overflow-y: auto; }
.ed-pages__list { position: relative; display: grid; gap: 14px; padding: 16px 20px 8px; }
.ed-pages__add { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 4px 20px calc(20px + var(--sab)); height: 38px; border-radius: 10px; border: 1.5px dashed var(--line-2); color: var(--ink-3); font-size: 13.5px; font-weight: 600; flex: none; }
.ed-pages__add:hover { color: var(--accent-ink); border-color: var(--accent); }
.ed-pages__add svg { width: 16px; height: 16px; }
.thumb { display: grid; gap: 6px; cursor: pointer; border-radius: 8px; touch-action: pan-y; position: relative; }
.thumb__paper { position: relative; width: 100%; border-radius: 4px; overflow: hidden; background: #fff; box-shadow: 0 0 0 1px var(--line-2), 0 2px 6px rgba(0,0,0,.06); transition: box-shadow 140ms var(--ease); }
.thumb__cv { display: block; width: 100%; height: 100%; }
.thumb.is-cur .thumb__paper { box-shadow: 0 0 0 2.5px var(--accent), 0 4px 12px rgba(59, 91, 219, .22); }
.thumb.is-drag { z-index: 2; opacity: 0.85; }
.thumb.is-drag .thumb__paper { box-shadow: var(--shadow-3); }
.thumb__foot { display: flex; align-items: center; justify-content: space-between; }
.thumb__num { font-size: 12px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; padding-left: 2px; }
.thumb.is-cur .thumb__num { color: var(--accent-ink); }
.thumb__more { width: 26px; height: 22px; border-radius: 6px; display: grid; place-items: center; color: var(--ink-3); }
.thumb__more:hover { background: var(--surface-2); color: var(--ink); }
.thumb__more svg { width: 16px; height: 16px; }
.thumb-drop { position: absolute; left: 14px; right: 14px; height: 3px; border-radius: 2px; background: var(--accent); pointer-events: none; }

.ed-view { position: relative; flex: 1; min-width: 0; overflow: hidden; touch-action: none; outline: none; cursor: crosshair; }
.ed-canvas { position: absolute; inset: 0; display: block; }
.ed-canvas--live { pointer-events: none; }
.ed-overlay { position: absolute; inset: 0; pointer-events: none; }
.ed-overlay > * { pointer-events: auto; }
.ed-text {
  position: absolute; margin: 0; border: 0; resize: none; overflow: hidden; background: rgba(59, 91, 219, 0.05);
  outline: 1.5px dashed var(--accent); outline-offset: 2px; border-radius: 2px; font-family: var(--font); transform-origin: 50% 50%;
  -webkit-user-select: text; user-select: text; caret-color: var(--accent); white-space: pre-wrap; overflow-wrap: anywhere; min-height: 1em;
}
.page-ind {
  position: absolute; left: 50%; bottom: calc(16px + var(--sab)); transform: translateX(-50%); z-index: 3;
  height: 30px; padding: 0 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700; color: var(--ink-2); font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: var(--shadow-1), 0 0 0 1px var(--line);
}
.add-end {
  position: absolute; left: 0; top: 0; z-index: 2; display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 16px 0 12px;
  border-radius: 999px; color: var(--ink-2); font-weight: 600; font-size: 14px; background: var(--surface); box-shadow: var(--shadow-1), 0 0 0 1px var(--line);
  transition: color 140ms, box-shadow 140ms;
}
.add-end svg { width: 18px; height: 18px; }
.add-end:hover { color: var(--accent-ink); box-shadow: var(--shadow-2), 0 0 0 1px var(--accent); }

.sel-bar {
  position: absolute; left: 0; top: 0; z-index: 4; display: flex; gap: 2px; padding: 4px; border-radius: 14px;
  background: #1f2430; color: #eef1f6; box-shadow: var(--shadow-3); animation: pop 160ms var(--ease);
}
:root[data-theme="dark"] .sel-bar { background: #2e333b; box-shadow: var(--shadow-3), 0 0 0 1px var(--line-2); }
.sel-bar__btn { display: grid; justify-items: center; gap: 1px; min-width: 52px; padding: 6px 6px 4px; border-radius: 10px; color: inherit; }
.sel-bar__btn svg { width: 19px; height: 19px; }
.sel-bar__btn:hover { background: rgba(255,255,255,.1); }
.sel-bar__btn.is-danger { color: #ff8a80; }
.sel-bar__label { font-size: 11px; font-weight: 600; opacity: 0.85; white-space: nowrap; }

/* ---------- 좁은 화면 ---------- */
@media (max-width: 900px) {
  .ed-title { max-width: 140px; }
  .ed-bar__sep { margin: 0 2px; }
  .tool { width: 40px; }
}
@media (max-width: 700px) {
  :root { --bar-h: 52px; }
  .ed-bar { gap: 2px; }
  .ed-title, .sync-dot { display: none; }
  .ed-bar__tools { overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; min-width: 0; }
  .ed-bar__tools::-webkit-scrollbar { display: none; }
  .ed-bar__left, .ed-bar__right { flex: none; }
  .ed-bar__right .icon-btn:nth-child(2) { display: none; }
  .tool { width: 38px; height: 40px; }
  .ed-sub { left: 10px; right: 10px; transform: none; max-width: none; }
  .ed.has-side .ed-pages { position: absolute; left: 0; top: 0; bottom: 0; z-index: 6; width: 150px; box-shadow: var(--shadow-3); }
  .sel-bar__label { display: none; }
  .sel-bar__btn { min-width: 40px; padding: 8px; }

  .lib-bar { gap: 8px; flex-wrap: wrap; }
  .lib-search { order: 3; flex-basis: 100%; max-width: none; margin: 0; }
  .lib-bar__right { margin-left: auto; }
  .acct__name, .sync-pill { display: none; }
  .lib-body { flex-direction: column; }
  .lib-side { width: auto; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; gap: 6px; scrollbar-width: none; }
  .lib-side::-webkit-scrollbar { display: none; }
  .lib-side__title { display: none; }
  .subj { width: auto; height: 34px; flex: none; border-radius: 999px; background: var(--surface-2); padding: 0 12px; }
  .subj--add { margin: 0; }
  .subj__more { display: none !important; }
  .subj__count { display: inline !important; }
  .lib-main { padding: 18px 16px calc(32px + var(--sab)); }
  .lib-title { font-size: 22px; }
  .nb-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 22px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
