/* ───── Палитра в духе приложения Claude ───── */
:root {
  --bg: #FAF9F5;
  --sidebar: #F3F1EA;
  --elev: #FFFFFF;
  --hover: rgba(31, 30, 29, .05);
  --active: rgba(31, 30, 29, .085);
  --border: rgba(31, 30, 29, .10);
  --border-strong: rgba(31, 30, 29, .18);
  --frame: #CFCDC6;
  --text: #141413;
  --text-2: #3D3D3A;
  --muted: #73726C;
  --faint: #A3A199;
  --accent: #C96442;
  --accent-hover: #B5573A;
  --accent-soft: rgba(201, 100, 66, .12);
  --on-accent: #FFFFFF;
  --danger: #B4432F;
  --mark: rgba(217, 119, 87, .28);
  --shadow: 0 12px 32px rgba(40, 30, 20, .12), 0 1px 3px rgba(40, 30, 20, .08);
  --toast-bg: #262624;
  --toast-text: #FAF9F5;

  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --note-font: var(--serif);
  --note-size: 17px;
  --side-w: 288px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #262624;
  --sidebar: #1F1E1D;
  --elev: #30302E;
  --hover: rgba(255, 255, 255, .045);
  --active: rgba(255, 255, 255, .08);
  --border: rgba(222, 220, 209, .10);
  --border-strong: rgba(222, 220, 209, .18);
  --frame: #4A4944;
  --text: #FAF9F5;
  --text-2: #C2C0B6;
  --muted: #9C9A92;
  --faint: #6F6E69;
  --accent: #D97757;
  --accent-hover: #E38A6C;
  --accent-soft: rgba(217, 119, 87, .16);
  --on-accent: #FFFFFF;
  --danger: #E0735E;
  --mark: rgba(217, 119, 87, .38);
  --shadow: 0 14px 36px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .3);
  --toast-bg: #FAF9F5;
  --toast-text: #141413;
  color-scheme: dark;
}

:root[data-font="sans"] { --note-font: var(--sans); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
html { background: var(--frame); }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .fill { fill: currentColor; }
.serif { font-family: var(--serif); }
.grow { flex: 1; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--faint); }
::-webkit-scrollbar-track { background: transparent; }

/* ───── Каркас ───── */
#app {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  border: 1px solid var(--frame);  /* углы скругляет подложка frame.py */
  overflow: hidden;
  background: var(--bg);
  transition: grid-template-columns .22s ease;
}
#app.loading { visibility: hidden; }
#app.collapsed { grid-template-columns: 0 1fr; }
#app.collapsed #sidebar { visibility: hidden; }
#app:not(.collapsed) .show-when-collapsed { display: none; }

.bar {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 8px;
  flex: none;
}
.icon-btn {
  width: 34px; height: 34px;
  display: inline-grid; place-items: center;
  border-radius: 9px;
  color: var(--muted);
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.icon-btn.danger:hover { background: #C42B1C; color: #fff; }

/* ───── Сайдбар ───── */
#sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0; min-height: 0;
  overflow: hidden;
}
.list { min-height: 0; }
.brand {
  font: 500 19px/1 var(--serif);
  letter-spacing: -.2px;
  margin-left: 6px;
  color: var(--text);
}
.side-top { padding: 4px 12px 10px; display: flex; flex-direction: column; gap: 8px; }

.new-btn {
  display: flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 10px 0 6px;
  border-radius: 11px;
  font-weight: 500;
  color: var(--text);
  transition: background .12s;
}
.new-btn:hover { background: var(--hover); }
.new-btn .plus {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
  transition: transform .15s, background .15s;
}
.new-btn .plus svg { width: 16px; height: 16px; stroke-width: 2.2; }
.new-btn:hover .plus { background: var(--accent-hover); transform: rotate(90deg); }
.new-btn kbd { margin-left: auto; font: 11px var(--sans); color: var(--faint); }

.search {
  display: flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 8px 0 12px;
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--muted);
  transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 16px; height: 16px; }
.search input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: transparent;
  font: 14px var(--sans); color: var(--text);
}
.search input::placeholder { color: var(--faint); }
.search .clear { display: none; width: 22px; height: 22px; border-radius: 6px; place-items: center; color: var(--faint); }
.search .clear:hover { background: var(--hover); color: var(--text); }
.search.has-text .clear { display: grid; }
.search .clear svg { width: 14px; height: 14px; }

.list { flex: 1; overflow-y: auto; padding: 0 0 12px; }
.group {
  font-size: 12px; font-weight: 500;
  color: var(--muted);
  padding: 14px 20px 6px;
  display: flex; align-items: center;
}
.group button { margin-left: auto; font-size: 12px; color: var(--accent); }
.group button:hover { text-decoration: underline; }
.list-hint { padding: 0 20px 6px; font-size: 12px; color: var(--faint); }

.item {
  margin: 1px 8px;
  padding: 9px 12px 10px;
  border-radius: 11px;
  cursor: pointer;
  transition: background .1s;
}
.item:hover { background: var(--hover); }
.item.active { background: var(--active); }
.item .row1 { display: flex; align-items: baseline; gap: 8px; }
.item .t {
  flex: 1; min-width: 0;
  font-weight: 600; font-size: 14px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item .t.untitled { color: var(--muted); font-weight: 500; }
.item .d { font-size: 11.5px; color: var(--faint); flex: none; }
.item .s {
  margin-top: 2px;
  font-size: 13px; line-height: 1.4; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-word;
}
.item .pin { width: 12px; height: 12px; color: var(--accent); align-self: center; stroke-width: 2; }
.item mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.list-empty { padding: 40px 24px; text-align: center; color: var(--muted); font-size: 13px; }
.list-empty .big { font: 17px/1.4 var(--serif); color: var(--text-2); margin-bottom: 4px; }

.side-bottom { padding: 8px; border-top: 1px solid var(--border); }
.side-link {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  height: 36px; padding: 0 12px;
  border-radius: 10px;
  color: var(--text-2);
}
.side-link:hover { background: var(--hover); }
.side-link.on { background: var(--active); color: var(--text); }
.side-link svg { width: 17px; height: 17px; color: var(--muted); }
.side-link .count { margin-left: auto; font-size: 12px; color: var(--faint); }

/* ───── Редактор ───── */
#pane {
  position: relative;
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  overflow: hidden;
  background: var(--bg);
}
.main-bar { padding-right: 6px; }
.meta { font-size: 12.5px; color: var(--muted); padding-left: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-state { font-size: 12px; color: var(--faint); display: flex; align-items: center; gap: 5px; margin-right: 6px; transition: opacity .3s; }
.save-state svg { width: 14px; height: 14px; stroke-width: 2; }
.save-state.error { color: var(--danger); }
.save-state.saving::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .25; } }

.toolbar {
  display: flex; align-items: center;
  padding: 2px 14px 8px 18px;
  gap: 2px;
}
.tools {
  display: flex; align-items: center; gap: 1px;
  padding: 3px;
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.tools button {
  width: 32px; height: 30px;
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--text-2);
  font-size: 14.5px;
  transition: background .1s, color .1s;
}
.tools button svg { width: 17px; height: 17px; }
.tools button:hover { background: var(--hover); color: var(--text); }
.tools button.on { background: var(--accent-soft); color: var(--accent); }
.tools .h { font-weight: 700; font-size: 16px; }
.tools .sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }

#btnPin.on svg { fill: currentColor; }

.scroll { flex: 1; min-height: 0; overflow-y: auto; cursor: text; }
.doc {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 44px 30vh;
  user-select: text;
}

.title {
  font: 500 30px/1.25 var(--serif);
  letter-spacing: -.3px;
  color: var(--text);
  outline: none;
  margin-bottom: 14px;
  position: relative;
  word-break: break-word;
}
.body {
  font-family: var(--note-font);
  font-size: var(--note-size);
  line-height: 1.65;
  color: var(--text);
  outline: none;
  min-height: 40vh;
  position: relative;
  word-break: break-word;
  caret-color: var(--accent);
}
.title.is-empty::before, .body.is-empty::before {
  content: attr(data-placeholder);
  position: absolute; left: 0; top: 0;
  color: var(--faint);
  pointer-events: none;
}
.title { caret-color: var(--accent); }
::selection { background: var(--mark); }

.body h2 { font: 600 1.4em/1.3 var(--serif); margin: .9em 0 .35em; letter-spacing: -.2px; }
.body h3 { font: 600 1.15em/1.35 var(--serif); margin: .8em 0 .3em; }
.body h2:first-child, .body h3:first-child { margin-top: 0; }
.body p { margin: 0 0 .6em; }
.body ul, .body ol { margin: .25em 0 .5em; padding-left: 1.6em; }
.body li { margin: .15em 0; padding-left: .15em; }
.body li::marker { color: var(--muted); }
.body blockquote {
  margin: .5em 0; padding: .1em 0 .1em 1em;
  border-left: 3px solid var(--accent);
  color: var(--text-2);
}
.body hr { border: 0; border-top: 1px solid var(--border-strong); margin: 1.2em 0; }
.body a { color: var(--accent); }
.body b, .body strong { font-weight: 700; }

.body ul.checklist { list-style: none; padding-left: .2em; }
.body ul.checklist > li { position: relative; padding-left: 1.85em; }
.body ul.checklist > li::before {
  content: '';
  position: absolute; left: .1em;
  top: calc((1.65em - 1.05em) / 2);
  width: 1.05em; height: 1.05em;
  border: 1.6px solid var(--faint);
  border-radius: .3em;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  box-sizing: border-box;
}
.body ul.checklist > li:hover::before { border-color: var(--accent); }
.body ul.checklist > li[data-checked="true"] { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--faint); }
.body ul.checklist > li[data-checked="true"]::before {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.3l2.6 2.6L12 5.5' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 85% no-repeat;
  border-color: var(--accent);
}

.foot {
  height: 34px; flex: none;
  display: flex; align-items: center;
  padding: 0 20px;
  font-size: 12px; color: var(--faint);
  border-top: 1px solid var(--border);
}

/* Режимы */
#pane.no-note .toolbar, #pane.no-note .scroll, #pane.no-note .foot, #pane.no-note .meta { display: none; }
#empty { display: none; }
#pane.no-note #empty { display: grid; flex: 1; place-items: center; }
.empty-inner { text-align: center; }
.empty-title { font: 500 24px/1.3 var(--serif); color: var(--text); margin-bottom: 6px; }
.empty-sub { color: var(--muted); margin-bottom: 18px; }

.trash-banner {
  display: none;
  align-items: center; gap: 8px;
  margin: 0 18px 6px; padding: 8px 8px 8px 14px;
  background: var(--accent-soft);
  border-radius: 12px;
  font-size: 13px; color: var(--text-2);
}
#pane.in-trash .trash-banner { display: flex; }
#pane.in-trash .toolbar { display: none; }

.btn {
  height: 32px; padding: 0 14px;
  border-radius: 9px;
  font-size: 13px; font-weight: 500;
  background: var(--elev);
  border: 1px solid var(--border-strong);
  color: var(--text);
  transition: background .12s;
}
.btn:hover { background: var(--hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); height: 38px; padding: 0 18px; }
.btn.accent:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }
.danger-text { color: var(--danger); }

/* Тост */
.toast {
  position: absolute; left: 50%; bottom: 52px;
  transform: translate(-50%, 16px);
  display: flex; align-items: center; gap: 14px;
  padding: 10px 10px 10px 16px;
  background: var(--toast-bg); color: var(--toast-text);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  white-space: nowrap;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { color: var(--accent); font-weight: 600; padding: 4px 8px; border-radius: 7px; }
.toast button:empty { display: none; }
.toast button:hover { background: rgba(128, 128, 128, .15); }

/* Настройки */
.popover {
  position: fixed; top: 46px; right: 10px;
  width: 300px;
  padding: 14px;
  background: var(--elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  z-index: 30;
  opacity: 0; transform: translateY(-6px) scale(.98); pointer-events: none;
  transform-origin: top right;
  transition: opacity .15s, transform .15s;
}
.popover.show { opacity: 1; transform: none; pointer-events: auto; }
.pop-title { font: 500 17px/1.2 var(--serif); margin: 2px 2px 12px; }
.popover .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 2px 12px; }
.popover .label { font-size: 13px; color: var(--text-2); }
.seg { display: flex; background: var(--hover); border-radius: 9px; padding: 2px; }
.seg button { font-size: 12px; padding: 5px 9px; border-radius: 7px; color: var(--muted); }
.seg button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
:root[data-theme="dark"] .seg button.on { background: #45443F; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 28px; height: 28px; border-radius: 8px; background: var(--hover); font-size: 16px; }
.stepper button:hover { background: var(--active); }
.stepper span { min-width: 26px; text-align: center; font-size: 13px; }
.switch { width: 38px; height: 22px; border-radius: 11px; background: var(--border-strong); position: relative; transition: background .15s; }
.switch span { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on span { transform: translateX(16px); }
.pop-sep { height: 1px; background: var(--border); margin: 4px 0 8px; }
.pop-link { display: block; width: 100%; text-align: left; font-size: 13px; padding: 7px 8px; border-radius: 8px; color: var(--text-2); }
.pop-link:hover { background: var(--hover); color: var(--text); }
.pop-note { font-size: 11.5px; color: var(--faint); padding: 8px 8px 0; }

/* Модалка */
.modal {
  position: fixed; inset: 0;
  background: rgba(20, 20, 19, .35);
  display: grid; place-items: center;
  z-index: 40;
  opacity: 0; pointer-events: none;
  transition: opacity .15s;
}
.modal.show { opacity: 1; pointer-events: auto; }
.modal-card {
  width: min(360px, calc(100vw - 32px));
  background: var(--elev);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
}
.modal-text { font: 16px/1.45 var(--serif); color: var(--text); margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ───── Компактная панель (окно на треть меньше) ───── */
@media (max-width: 760px) {
  :root { --side-w: 216px; }
  .side-top { padding: 2px 10px 8px; }
  .new-btn kbd { display: none; }
  .item { margin: 1px 6px; padding: 8px 10px 9px; }
  .group { padding: 12px 16px 5px; }
  .toolbar { padding: 0 8px 6px 12px; }
  .tools button { width: 28px; height: 28px; }
  .tools button[data-cmd="underline"], .tools button[data-cmd="removeFormat"] { display: none; }
  .tools .sep { margin: 0 2px; }
  .icon-btn { width: 30px; height: 30px; }
  .doc { padding: 12px 26px 30vh; }
  .title { font-size: 25px; margin-bottom: 10px; }
  .foot { padding: 0 14px; }
  .foot .hint { display: none; }
  .meta { padding-left: 6px; }
  .popover { width: 290px; }
}

/* ───── Выбор персонажа ───── */
.btn.small { height: 28px; padding: 0 12px; font-size: 12.5px; }
.picker {
  position: fixed; inset: 0; z-index: 35;
  background: rgba(20, 20, 19, .28);
  display: flex; padding: 14px;
  opacity: 0; pointer-events: none;
  transition: opacity .18s;
}
.picker.show { opacity: 1; pointer-events: auto; }
.picker-card {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  transform: translateY(10px) scale(.985);
  transition: transform .22s cubic-bezier(.2, .8, .3, 1);
  overflow: hidden;
}
.picker.show .picker-card { transform: none; }
.picker-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 14px 6px 22px; }
.picker-head > div { flex: 1; }
.picker-title { font: 500 23px/1.2 var(--serif); letter-spacing: -.2px; }
.picker-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 22px 12px; }
.chip {
  height: 30px; padding: 0 13px;
  border-radius: 15px;
  font-size: 13px; color: var(--text-2);
  background: var(--hover);
  transition: background .12s, color .12s;
}
.chip:hover { background: var(--active); }
.chip.on { background: var(--text); color: var(--bg); }
.chip .n { opacity: .55; margin-left: 5px; font-size: 12px; }
.picker-grid {
  flex: 1; overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  grid-auto-rows: max-content;
  gap: 12px;
  padding: 4px 22px 22px;
  align-content: start;
}
.pcard {
  position: relative;
  border-radius: 16px;
  background:
    radial-gradient(120% 70% at 50% 100%, var(--accent-soft), transparent 70%),
    var(--sidebar);
  border: 1px solid var(--border);
  cursor: pointer;
  overflow: hidden;
  transition: transform .18s, box-shadow .18s, border-color .18s;
  animation: pop .35s both;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } }
.pcard:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(40, 30, 20, .12); }
.pcard .pic { aspect-ratio: 1 / 1.08; display: grid; place-items: center; padding: 10px 8px 0; }
.pcard img {
  width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .18));
  transition: transform .25s cubic-bezier(.2, .8, .3, 1.4);
}
.pcard:hover img { transform: translateY(-4px) scale(1.05); }
.pcard .pname { font-size: 12.5px; color: var(--text-2); text-align: center; padding: 6px 8px 10px; }
.pcard.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), 0 10px 26px rgba(201, 100, 66, .22); }
.pcard.on .pname { color: var(--accent); font-weight: 600; }
.pcard .check {
  position: absolute; top: 9px; right: 9px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: none; place-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}
.pcard .check svg { width: 14px; height: 14px; stroke-width: 2.6; }
.pcard.on .check { display: grid; }

/* ───── Синхронизация ───── */
.sync-status { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); text-align: right; }
.sync-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.sync-status.ok .dot { background: #4f9d69; box-shadow: 0 0 0 3px rgba(79, 157, 105, .18); }
.sync-status.wait .dot { background: var(--accent); animation: pulse 1s infinite; }
.sync-status.warn .dot { background: #d9a13b; }
.sync-status.err .dot { background: var(--danger); }
.btn.wide { width: 100%; height: 34px; margin: 0 0 12px; }

.code-card { text-align: center; width: min(380px, calc(100vw - 32px)); }
.code-title { font: 500 19px/1.3 var(--serif); margin-bottom: 14px; }
.code-value {
  font: 600 42px/1 "Cascadia Mono", Consolas, monospace;
  letter-spacing: 6px;
  color: var(--accent);
  padding: 16px 0;
  background: var(--accent-soft);
  border-radius: 14px;
  margin-bottom: 14px;
}
.code-hint { font-size: 13px; color: var(--text-2); line-height: 1.5; margin-bottom: 18px; }
.code-card .modal-actions { justify-content: center; }

/* ───── Экран привязки (телефон) ───── */
.pair {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: none; place-items: center;
  padding: 24px;
}
.pair.show { display: grid; }
.pair-card { width: min(360px, 100%); text-align: center; }
.pair-logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 18px; box-shadow: 0 10px 30px rgba(201, 100, 66, .3); }
.pair-title { font: 500 26px/1.25 var(--serif); margin-bottom: 8px; }
.pair-sub { color: var(--muted); font-size: 14.5px; line-height: 1.5; margin-bottom: 24px; }
.pair-input {
  width: 100%; height: 64px;
  text-align: center;
  font: 600 32px/1 "Cascadia Mono", ui-monospace, Menlo, monospace;
  letter-spacing: 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: 16px;
  background: var(--elev); color: var(--text);
  outline: none;
  margin-bottom: 14px;
}
.pair-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.pair-input::placeholder { color: var(--faint); }
.pair-go { width: 100%; height: 50px; font-size: 16px; border-radius: 14px; }
.pair-err { min-height: 22px; margin-top: 12px; color: var(--danger); font-size: 13.5px; }

/* ───── Режимы ───── */
.web-only, .mobile-only { display: none !important; }
.web .web-only { display: inline-grid !important; }
.web .desktop-only { display: none !important; }
.web #app, #app.web { border: 0; }

/* ───── Телефон ───── */
@media (max-width: 640px) {
  #app.web {
    grid-template-columns: minmax(0, 1fr);
    width: 100vw;
    height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
    transition: none;
  }
  #app.web #sidebar { grid-area: 1 / 1; border-right: 0; background: var(--bg); min-width: 0; width: 100%; }
  #app.web .main-bar .meta { flex: 1; min-width: 0; }
  #app.web .main-bar .grow { display: none; }
  #app.web #pane { grid-area: 1 / 1; visibility: hidden; transform: translateX(24px); opacity: 0;
    transition: transform .22s ease, opacity .18s ease, visibility 0s .22s; }
  #app.web.m-note #pane { visibility: visible; transform: none; opacity: 1; transition: transform .22s ease, opacity .18s ease; }
  #app.web.m-note #sidebar { visibility: hidden; }
  #app.web .mobile-only { display: inline-grid !important; }
  #app.web #btnSidebar, #app.web .show-when-collapsed { display: none !important; }
  #app.web .bar { height: 52px; }
  #app.web .brand { font-size: 24px; margin-left: 10px; }
  #app.web .side-top { padding: 4px 14px 10px; }
  #app.web .search input { font-size: 16px; }
  #app.web .search { height: 44px; border-radius: 13px; }
  #app.web .new-btn { height: 46px; font-size: 15px; }
  #app.web .item { margin: 2px 10px; padding: 12px 14px; }
  #app.web .item .t { font-size: 15.5px; }
  #app.web .item .s { font-size: 14px; }
  #app.web .side-bottom { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  #app.web .toolbar { overflow-x: auto; padding: 0 10px 8px; scrollbar-width: none; }
  #app.web .toolbar::-webkit-scrollbar { display: none; }
  #app.web .tools button { width: 36px; height: 34px; }
  #app.web .tools button[data-cmd="underline"], #app.web .tools button[data-cmd="removeFormat"] { display: grid; }
  #app.web .doc { padding: 10px 20px 40vh; }
  #app.web .title { font-size: 27px; }
  #app.web .foot { padding-bottom: env(safe-area-inset-bottom); height: calc(34px + env(safe-area-inset-bottom)); }
  #app.web .foot .hint { display: none; }
  #app.web .popover {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; width: auto;
    border-radius: 20px 20px 0 0;
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
    transform: translateY(20px);
  }
  #app.web .popover.show { transform: none; }
  #app.web .toast { bottom: calc(52px + env(safe-area-inset-bottom)); }
}

/* ───── Аккаунт в настройках ───── */
.acct { background: var(--hover); border-radius: 14px; padding: 12px; margin: 2px 0 12px; }
.acct-row { display: flex; align-items: center; gap: 11px; margin-bottom: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font: 600 17px/1 var(--serif);
  background: var(--border-strong); color: var(--bg);
}
.avatar.on { background: var(--accent); color: #fff; }
.acct-info { min-width: 0; }
.acct-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct .sync-status { justify-content: flex-start; text-align: left; margin-top: 2px; }
.acct-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.acct-actions .btn.accent { height: 30px; }
#btnSettings.dot { position: relative; }
#btnSettings.dot::after {
  content: ''; position: absolute; top: 6px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
}

/* ───── Экран входа ───── */
.auth {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: grid; place-items: center;
  padding: 24px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  overflow-y: auto;
}
.auth.show { opacity: 1; pointer-events: auto; }
.auth-card { width: min(360px, 100%); text-align: center; position: relative; padding-top: 6px; }
.auth-close { position: fixed; top: 12px; right: 12px; }
.auth-logo { width: 64px; height: 64px; border-radius: 17px; margin-bottom: 16px; box-shadow: 0 10px 28px rgba(201, 100, 66, .28); }
.auth-title { font: 500 26px/1.2 var(--serif); margin-bottom: 8px; letter-spacing: -.2px; }
.auth-sub { color: var(--muted); font-size: 14px; line-height: 1.5; margin-bottom: 18px; min-height: 21px; }
.auth-tabs { display: flex; background: var(--hover); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.auth-tabs button { flex: 1; height: 34px; border-radius: 9px; font-size: 13.5px; color: var(--muted); }
.auth-tabs button.on { background: var(--elev); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 500; }
#authForm { display: flex; flex-direction: column; gap: 9px; }
.auth-input {
  height: 48px; padding: 0 16px;
  border: 1.5px solid var(--border-strong); border-radius: 13px;
  background: var(--elev); color: var(--text);
  font: 16px var(--sans);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.auth-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.auth-input::placeholder { color: var(--faint); }
.auth .pair-input { margin-bottom: 0; }
.auth-go { height: 50px; font-size: 15.5px; border-radius: 13px; margin-top: 4px; }
.auth-go:disabled { opacity: .6; }
.auth-err { min-height: 20px; color: var(--danger); font-size: 13.5px; }
.auth-skip { margin-top: 6px; font-size: 13px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.auth-skip:hover { color: var(--text); }

/* ───── Положение окна и размер персонажа ───── */
.popover { max-height: calc(100vh - 58px); overflow-y: auto; }
.sub-label { margin: 2px 2px 8px; }
.layout-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.layout-list button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  padding: 9px 10px 8px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--bg);
  text-align: left; transition: border-color .12s, background .12s;
}
.layout-list button:hover { border-color: var(--border-strong); }
.layout-list button svg { width: 22px; height: 22px; color: var(--muted); margin-bottom: 4px; }
.layout-list button b { font-size: 12px; font-weight: 600; line-height: 1.25; }
.layout-list button span { font-size: 11px; color: var(--muted); line-height: 1.3; }
.layout-list button.on { border-color: var(--accent); background: var(--accent-soft); }
.layout-list button.on svg { color: var(--accent); }
.slider-row { margin-bottom: 4px !important; }
.slider-val { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.range { width: 100%; margin: 4px 0 14px; accent-color: var(--accent); cursor: pointer; }

.grips div { position: fixed; z-index: 26; display: none; }
.grips [data-edge="l"] { left: 0; top: 14px; bottom: 14px; width: 7px; cursor: ew-resize; }
.grips [data-edge="r"] { right: 0; top: 14px; bottom: 14px; width: 7px; cursor: ew-resize; }
.grips [data-edge="t"] { top: 0; left: 14px; right: 14px; height: 6px; cursor: ns-resize; }
.grips [data-edge="b"] { bottom: 0; left: 14px; right: 14px; height: 7px; cursor: ns-resize; }
.grips [data-edge="tl"] { top: 0; left: 0; width: 14px; height: 14px; cursor: nwse-resize; }
.grips [data-edge="br"] { bottom: 0; right: 0; width: 14px; height: 14px; cursor: nwse-resize; }
.grips [data-edge="tr"] { top: 0; right: 0; width: 14px; height: 14px; cursor: nesw-resize; }
.grips [data-edge="bl"] { bottom: 0; left: 0; width: 14px; height: 14px; cursor: nesw-resize; }
#app.movable .bar { cursor: move; }
#app.movable .bar button, #app.movable .bar input { cursor: pointer; }

/* ───── Обновления ───── */
.update-bar {
  display: none; align-items: center; gap: 8px;
  margin: 0 10px 8px; padding: 10px 8px 10px 12px;
  border-radius: 12px; background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  animation: pop .3s both;
}
.update-bar.show { display: flex; }
.ub-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ub-text b { font-size: 13px; font-weight: 600; }
.ub-text span { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ub-close { width: 22px; height: 22px; border-radius: 6px; color: var(--muted); font-size: 16px; line-height: 1; }
.ub-close:hover { background: var(--hover); color: var(--text); }
.version-row .label { font-size: 12.5px; color: var(--muted); }

/* ───── Перетаскивание заметки в новое окно ───── */
.item.dragging { opacity: .45; transform: scale(.97); }
.drag-hint {
  position: fixed; left: 50%; bottom: 46px; z-index: 28;
  transform: translate(-50%, 10px);
  max-width: calc(100% - 24px);
  padding: 9px 14px; border-radius: 12px;
  background: var(--toast-bg); color: var(--toast-text);
  font-size: 12.5px; font-weight: 500; text-align: center;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity .15s, transform .15s, background .15s;
}
.drag-hint.show { opacity: 1; transform: translate(-50%, 0); }
.drag-hint.out { background: var(--accent); color: #fff; }
