/* Шрифты: только локальные/system-ui — без @import (CSP и офлайн). */
:root {
  --toc-width: 204px;
  --accent: hsl(347, 77%, 50%);
  /* запас под фиксированный футер + safe-area (долистать низ зумированной страницы) */
  --viewer-footer-pad: max(1.25rem, calc(4.85rem + env(safe-area-inset-bottom, 0px)));
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #1a1b1e;
  color: #e4e4e7;
  min-height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: #25262b;
  border-bottom: 1px solid #3f3f46;
  flex-shrink: 0;
}

.toolbar-start {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
  min-width: 0;
}

.toolbar-leading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.toolbar-end {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: nowrap;
  justify-content: flex-end;
  margin-left: auto;
  min-width: 0;
}

.toolbar h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.05em;
  animation: glitch 6s infinite;
  text-shadow: 0 0 8px hsla(347, 100%, 55%, 0.4), 0 0 30px hsla(347, 100%, 40%, 0.25);
}

.toolbar .logo-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

@keyframes glitch {
  0%, 100% { text-shadow: 1px 0 hsla(347, 100%, 55%, 0.35), -1px 0 hsla(200, 100%, 55%, 0.35), 0 0 8px hsla(347, 100%, 55%, 0.4), 0 0 30px hsla(347, 100%, 40%, 0.25); }
  25% { text-shadow: -1px 0 hsla(347, 100%, 55%, 0.35), 1px 0 hsla(200, 100%, 55%, 0.35), 0 0 8px hsla(347, 100%, 55%, 0.4), 0 0 30px hsla(347, 100%, 40%, 0.25); }
  50% { text-shadow: 1px 1px hsla(347, 100%, 55%, 0.35), -1px -1px hsla(200, 100%, 55%, 0.35), 0 0 8px hsla(347, 100%, 55%, 0.4), 0 0 30px hsla(347, 100%, 40%, 0.25); }
  75% { text-shadow: -1px 1px hsla(347, 100%, 55%, 0.35), 1px -1px hsla(200, 100%, 55%, 0.35), 0 0 8px hsla(347, 100%, 55%, 0.4), 0 0 30px hsla(347, 100%, 40%, 0.25); }
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: nowrap;
  min-width: 0;
}

/* Квадратные кнопки шапки (как «?»): градиент, рамка */
.toolbar-icon-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid #52525b;
  background: linear-gradient(145deg, #2d2e33 0%, #1f2024 100%);
  color: #e4e4e7;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, color 0.2s, transform 0.15s, background 0.2s;
}

.toolbar-icon-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 1px hsla(347, 77%, 50%, 0.35), 0 0 20px hsla(347, 77%, 45%, 0.2);
}

.toolbar-icon-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.toolbar-icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.toolbar-icon-btn--help:hover:not(:disabled) {
  border-color: var(--accent);
}

.toolbar-icon-btn--add {
  color: #4ade80;
}

.toolbar-icon-btn--add:hover:not(:disabled) {
  border-color: #22c55e;
  color: #86efac;
  box-shadow: 0 0 0 1px hsla(142, 71%, 45%, 0.4), 0 0 18px hsla(142, 71%, 40%, 0.2);
}

.toolbar-icon-btn--primary {
  background: linear-gradient(145deg, hsl(347, 72%, 48%) 0%, hsl(347, 75%, 36%) 100%);
  border-color: hsl(347, 70%, 42%);
  color: #fff;
}

.toolbar-icon-btn--primary:hover:not(:disabled) {
  border-color: hsl(347, 77%, 62%);
  box-shadow: 0 0 0 1px hsla(347, 77%, 55%, 0.45), 0 0 20px hsla(347, 77%, 45%, 0.25);
}

.toolbar-icon-btn--primary:disabled {
  background: linear-gradient(145deg, hsl(347, 35%, 28%) 0%, hsl(347, 30%, 22%) 100%);
  border-color: #52525b;
  color: #a1a1aa;
}

.toolbar-icon-btn .icon-undo,
.toolbar-icon-btn .icon-redo {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background-color: hsl(347, 72%, 46%);
  position: relative;
  overflow: hidden;
}

/* Шеврон отдельным слоем: фильтр даёт чистый белый, красный фон кнопки не трогаем */
.toolbar-icon-btn .icon-undo::after,
.toolbar-icon-btn .icon-redo::after {
  content: "";
  display: block;
  width: 72%;
  height: 72%;
  background-image: url("undo-chevron.png");
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  filter: brightness(0) invert(1);
  transform-origin: 50% 50%;
}

.toolbar-icon-btn .icon-redo::after {
  transform: rotate(180deg);
}

.toolbar-help-icon {
  width: 22px;
  height: 22px;
}

.add-icon {
  display: block;
  color: inherit;
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1;
}

/* Текстовые кнопки шапки: без капса, первая буква как в подписи */
.toolbar-text-btn {
  flex-shrink: 0;
  padding: 0.5rem 0.9rem;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.02em;
  text-transform: none;
  border-radius: 10px;
  border: 1px solid #52525b;
  background: linear-gradient(145deg, #2d2e33 0%, #1f2024 100%);
  color: #e4e4e7;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, color 0.2s, transform 0.15s, background 0.2s;
}

.toolbar-text-btn:hover {
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 1px hsla(347, 77%, 50%, 0.35), 0 0 20px hsla(347, 77%, 45%, 0.15);
}

.toolbar-text-btn:active {
  transform: scale(0.98);
}

/* Высота как у .toolbar-icon-btn (38px) */
.toolbar-text-btn--compact {
  height: 38px;
  padding: 0 0.85rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toolbar-text-btn--outline {
  background: transparent;
  border-color: var(--accent);
  color: hsl(347, 85%, 68%);
}

.toolbar-text-btn--outline:hover {
  background: hsla(347, 77%, 50%, 0.12);
  color: #fff;
  border-color: hsl(347, 77%, 58%);
}

.zoom {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 1;
  min-width: 0;
}

.zoom-value {
  flex-shrink: 0;
  min-width: 2.75rem;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: #a1a1aa;
  text-align: right;
}

/* Ползунок: бегунок «асфальт», без системной синей обводки фокуса */
.zoom input[type="range"] {
  width: 100px;
  max-width: 100%;
  flex: 0 1 100px;
  height: 18px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.zoom input[type="range"]:focus {
  outline: none;
}

.zoom input[type="range"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px #3f3f46;
  border-radius: 6px;
}

.zoom input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

.zoom input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: #45454d;
  border: 1px solid #5c5c64;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.zoom input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

.zoom input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

.zoom input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 1px solid #5c5c64;
  border-radius: 50%;
  background: #45454d;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

.toc-empty-hint {
  margin: 0;
  padding: 0.65rem 0.75rem;
  font-size: 0.72rem;
  line-height: 1.35;
  color: #71717a;
  text-align: center;
  border-bottom: 1px solid #3f3f46;
  flex-shrink: 0;
}

/* Зона загрузки в области просмотра */
.upload-zone {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  width: min(72vmin, 400px);
  height: min(72vmin, 400px);
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: hsla(347, 35%, 22%, 0.35);
  backdrop-filter: blur(4px);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

/* Логотип внутри зоны: <img> — border-radius стабильно обрезает растр (в отличие от background на ::before) */
.upload-zone-logo {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(72%, 240px);
  height: min(52%, 200px);
  object-fit: contain;
  object-position: center;
  border-radius: 14px;
  opacity: 0.16;
  pointer-events: none;
  z-index: 0;
  user-select: none;
  -webkit-user-drag: none;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: hsl(347, 77%, 58%);
  background: hsla(347, 40%, 28%, 0.45);
  box-shadow: 0 0 0 1px hsla(347, 77%, 50%, 0.25), 0 0 24px hsla(347, 77%, 45%, 0.15);
}

.upload-zone:hover .upload-zone-logo,
.upload-zone.dragover .upload-zone-logo {
  opacity: 0.22;
}

.upload-zone p {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: 16rem;
  text-align: center;
  color: #e4e4e7;
  font-size: 1.05rem;
  line-height: 1.45;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.75);
}

.editor {
  flex: 1 1 0;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.toc {
  width: var(--toc-width);
  flex-shrink: 0;
  min-height: 0;
  background: #25262b;
  border-right: 1px solid #3f3f46;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toc-header {
  padding: 0.75rem 1rem;
  font-weight: 600;
  border-bottom: 1px solid #3f3f46;
  flex-shrink: 0;
  background: #25262b;
}

.toc-scroll {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: scroll;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #52525b #1a1b1e;
}

.toc-scroll::-webkit-scrollbar {
  width: 8px;
}

.toc-scroll::-webkit-scrollbar-track {
  background: #1a1b1e;
  border-radius: 4px;
}

.toc-scroll::-webkit-scrollbar-thumb {
  background: #52525b;
  border-radius: 4px;
  border: 2px solid #1a1b1e;
}

.toc-scroll::-webkit-scrollbar-thumb:hover {
  background: #71717a;
}

.page-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  padding-bottom: 4rem;
}

.page-list li {
  padding: 0.35rem 0.5rem;
  margin-bottom: 2px;
  border-radius: 6px;
  cursor: grab;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.page-list li > span {
  white-space: nowrap;
  flex-shrink: 0;
}

.page-list .page-thumb {
  width: 36px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  background: #3f3f46;
}

.page-list li:hover {
  background: #3f3f46;
}

.page-list li.active {
  background: var(--accent);
  color: #fff;
}

.page-list li.deleted {
  opacity: 0.5;
  text-decoration: line-through;
}

.page-list li.dragging {
  opacity: 0.5;
  transform: scale(0.95);
  transition: transform 0.15s ease, opacity 0.15s ease;
  cursor: grabbing;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.page-list li.drag-over {
  background: var(--accent);
  color: #fff;
  transform: scale(1.02);
  transition: transform 0.15s ease, background 0.15s ease;
  box-shadow: 0 0 0 2px var(--accent);
}

.viewer {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* иначе зумированная страница задаёт min-height колонки и футер уезжает за экран */
  min-height: 0;
  overflow: hidden;
  position: relative;
}

/* Внешний блок только режет высоту (flex); скролл внутри .page-scroll — иначе scrollHeight часто не растёт */
.page-container {
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page-scroll {
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  text-align: center;
  padding: 1rem;
  padding-bottom: var(--viewer-footer-pad);
  scroll-padding-bottom: var(--viewer-footer-pad);
  position: relative;
}

.editor--empty .page-scroll {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: initial;
}

.page-strip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  width: 100%;
  box-sizing: border-box;
}

.page-scroll > .page-strip {
  z-index: 1;
  text-align: center;
}

.page-image-wrap {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  min-width: 0;
  /* Плейсхолдер до загрузки bitmap: нулевая площадь ломает IntersectionObserver и скролл-ленту */
  min-height: 6rem;
  background: #1f2024;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  scroll-margin-top: 0.75rem;
  scroll-margin-bottom: 1.5rem;
}

.inline-layer-host {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
  visibility: hidden;
}

.page-image-wrap img {
  display: block;
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  user-drag: none;
  pointer-events: none;
}

.selection-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.page-image-wrap .selection-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  z-index: 2;
  pointer-events: auto;
  touch-action: auto;
}

.page-image-wrap .text-inline-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  pointer-events: none;
}

.page-image-wrap .text-inline-editor {
  position: absolute;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  outline: 2px solid rgba(220, 38, 38, 0.9);
  outline-offset: 0;
  resize: none;
  overflow: hidden;
  max-width: calc(100% - 2px);
  max-height: calc(100% - 2px);
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: none;
  background: transparent !important;
  letter-spacing: normal;
  word-spacing: normal;
  white-space: pre-wrap;
  tab-size: 1;
  caret-color: auto;
  line-height: 1.05;
}

.page-nav {
  position: fixed;
  bottom: 0;
  left: var(--toc-width);
  right: 0;
  z-index: 90;
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  padding-bottom: max(0.75rem, calc(0.75rem + env(safe-area-inset-bottom, 0px)));
  display: flex;
  align-items: center;
  justify-content: center;
  background: #25262b;
  border-top: 1px solid #3f3f46;
}

.page-nav-center {
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-version {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  color: #71717a;
}

.page-nav-btn {
  padding: 0.45rem 0.95rem;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.02em;
  text-transform: none;
  border-radius: 10px;
  border: 1px solid #52525b;
  background: linear-gradient(145deg, #2d2e33 0%, #1f2024 100%);
  color: #e4e4e7;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, color 0.2s, transform 0.15s, background 0.2s;
}

.page-nav-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 1px hsla(347, 77%, 50%, 0.35), 0 0 18px hsla(347, 77%, 45%, 0.15);
}

.page-nav-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.page-nav-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.page-nav-btn-icon {
  display: none;
}

.page-nav-btn-text {
  display: inline;
}

#btnPrev {
  margin-right: 14px;
}

#btnNext {
  margin-left: 14px;
}

#pageIndicator {
  font-size: 0.9rem;
  color: #a1a1aa;
}

/* Контекстное меню (ПКМ) */
.context-menu {
  position: fixed;
  z-index: 10000;
  min-width: 200px;
  padding: 4px 0;
  background: #2a2a2a;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  border: 1px solid #3f3f46;
  display: none;
}

.context-menu.is-open {
  display: block;
}

.context-menu .ctx-item {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: #e4e4e7;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.context-menu .ctx-item:hover {
  background: #ff5252;
  color: #fff;
}

.context-menu .ctx-item:first-child {
  border-radius: 6px 6px 0 0;
}

.context-menu .ctx-item:last-child {
  border-radius: 0 0 6px 6px;
}

.context-menu .ctx-separator {
  height: 1px;
  background: #444;
  margin: 4px 8px;
}

.context-menu .ctx-submenu {
  position: relative;
}

.context-menu .ctx-submenu > .ctx-item::after {
  content: "▸";
  float: right;
  font-size: 0.8rem;
  opacity: 0.8;
}

.context-menu .ctx-submenu ul {
  display: none;
  list-style: none;
  margin: 0;
  padding: 4px 0;
  position: absolute;
  left: 100%;
  top: 0;
  margin-left: -4px;
  min-width: 180px;
  background: #2a2a2a;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  border: 1px solid #3f3f46;
}

.context-menu .ctx-submenu:hover ul {
  display: block;
}

.context-menu .ctx-submenu ul .ctx-item {
  padding: 8px 14px;
  border-radius: 0;
}

.context-menu .ctx-submenu ul .ctx-item:first-child {
  border-radius: 6px 6px 0 0;
}

.context-menu .ctx-submenu ul .ctx-item:last-child {
  border-radius: 0 0 6px 6px;
}

/* ——— Онбординг ——— */
.onboarding-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10050;
  background: rgba(8, 8, 12, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.onboarding-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.onboarding-modal {
  position: fixed;
  inset: 0;
  z-index: 10051;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.onboarding-modal.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.onboarding-modal[hidden] {
  display: none !important;
}

.onboarding-card {
  --onboarding-card-height: min(88vh, 640px);
  width: min(100%, 720px);
  height: var(--onboarding-card-height);
  max-height: var(--onboarding-card-height);
  display: flex;
  flex-direction: column;
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(165deg, #2a2b31 0%, #1e1f24 55%, #18191d 100%);
  border: 1px solid #3f3f46;
  border-radius: 18px;
  box-shadow:
    0 0 0 1px hsla(347, 77%, 50%, 0.12),
    0 24px 64px rgba(0, 0, 0, 0.55),
    0 0 80px hsla(347, 60%, 40%, 0.08);
  overflow: hidden;
  transform: translateY(12px) scale(0.98);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.onboarding-modal.is-open .onboarding-card {
  transform: translateY(0) scale(1);
}

.onboarding-header {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.15rem 0.85rem;
  border-bottom: 1px solid #3f3f46;
  background: linear-gradient(90deg, hsla(347, 50%, 45%, 0.08) 0%, transparent 55%);
}

.onboarding-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.onboarding-badge {
  flex-shrink: 0;
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  padding: 0.25rem 0.45rem;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  line-height: 1;
}

.onboarding-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.25;
  color: #fafafa;
  letter-spacing: -0.02em;
}

.onboarding-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: #3f3f46;
  color: #e4e4e7;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.onboarding-close:hover {
  background: var(--accent);
  color: #fff;
}

.onboarding-body {
  display: grid;
  grid-template-columns: minmax(168px, 210px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  flex: 1;
  align-items: stretch;
}

.onboarding-tabs {
  min-height: 0;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0.35rem;
  padding: 0.85rem 0.65rem;
  border-bottom: none;
  border-right: 1px solid #3a3a42;
  background: rgba(0, 0, 0, 0.22);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.onboarding-tab {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.4rem;
  flex: 0 0 auto;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #a1a1aa;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  cursor: pointer;
  text-align: left;
  line-height: 1.25;
  transition:
    color 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.onboarding-tab:hover {
  color: #fafafa;
  background: linear-gradient(90deg, hsla(347, 77%, 50%, 0.14) 0%, #35363c 40%);
  border-color: hsla(347, 77%, 50%, 0.35);
  transform: translateX(3px);
  box-shadow:
    0 0 0 1px hsla(347, 77%, 50%, 0.12),
    -3px 0 14px hsla(347, 77%, 45%, 0.15);
}

.onboarding-tab.is-active {
  color: #fff;
  background: linear-gradient(90deg, hsla(347, 77%, 50%, 0.22) 0%, hsla(347, 40%, 28%, 0.55) 100%);
  border-color: hsla(347, 77%, 50%, 0.5);
  transform: translateX(2px);
  box-shadow:
    0 0 0 1px hsla(347, 77%, 50%, 0.2),
    inset 3px 0 0 0 var(--accent);
}

.onboarding-tab.is-active:hover {
  border-color: hsla(347, 77%, 58%, 0.65);
  box-shadow:
    0 0 0 1px hsla(347, 77%, 50%, 0.28),
    inset 3px 0 0 0 var(--accent),
    -2px 0 18px hsla(347, 77%, 40%, 0.2);
}

.onboarding-tab-emoji {
  font-size: 1rem;
  line-height: 1;
}

.onboarding-panels {
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 1.15rem 1.25rem;
  -webkit-overflow-scrolling: touch;
}

.onboarding-panel {
  display: none;
  animation: onboardingFade 0.28s ease;
}

.onboarding-panel.is-active {
  display: block;
}

@keyframes onboardingFade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.onboarding-lead {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #a1a1aa;
}

.onboarding-hint {
  margin: 0 0 1rem;
  padding: 0.65rem 0.75rem;
  font-size: 0.82rem;
  line-height: 1.45;
  color: #d4d4d8;
  background: hsla(347, 40%, 50%, 0.1);
  border-radius: 10px;
  border: 1px solid hsla(347, 50%, 45%, 0.2);
}

.onboarding-block {
  margin-bottom: 1.15rem;
}

.onboarding-block:last-child {
  margin-bottom: 0;
}

.onboarding-block-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #f4f4f5;
  letter-spacing: -0.01em;
}

.onboarding-list,
.onboarding-steps {
  margin: 0;
  padding-left: 1.2rem;
  color: #c4c4cc;
  font-size: 0.86rem;
  line-height: 1.55;
}

.onboarding-list li,
.onboarding-steps li {
  margin-bottom: 0.35rem;
}

.onboarding-text {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.55;
  color: #c4c4cc;
}

.onboarding-arrow {
  color: var(--accent);
  font-weight: 700;
  margin-right: 0.25rem;
}

.onboarding-block strong {
  color: #fafafa;
  font-weight: 600;
}

@media (max-width: 560px) {
  .onboarding-card {
    width: min(100%, 520px);
    --onboarding-card-height: min(86vh, 580px);
  }

  .onboarding-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .onboarding-tabs {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid #3a3a42;
    padding: 0.65rem 0.75rem 0.55rem;
  }

  .onboarding-tab {
    flex: 1 1 auto;
    font-size: 0.72rem;
    padding: 0.42rem 0.5rem;
  }

  .onboarding-tab-emoji {
    display: none;
  }

  .onboarding-panels {
    padding: 0.85rem 1rem 1.1rem;
  }
}

/* Планшеты и узкие окна: шапка не в одну линию — кнопки не наезжают друг на друга */
@media (max-width: 880px) {
  :root {
    --toc-width: 168px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.55rem 0.7rem;
  }

  .toolbar-start {
    flex-wrap: wrap;
    align-items: center;
    row-gap: 0.35rem;
    column-gap: 0.65rem;
  }

  .toolbar h1 {
    font-size: 1.05rem;
  }

  .toolbar-end {
    margin-left: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    min-width: 0;
  }

  .toolbar-actions {
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    row-gap: 0.45rem;
    width: 100%;
    min-width: 0;
  }

  /* Зум на отдельной строке на всю ширину блока действий */
  .toolbar-actions .zoom {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    justify-content: flex-start;
  }

  .toolbar-actions .zoom input[type="range"] {
    flex: 1 1 auto;
    width: auto;
    min-width: 72px;
    max-width: none;
  }

  .toolbar-text-btn {
    padding: 0.42rem 0.65rem;
    font-size: 0.75rem;
  }

  .toolbar #btnOpenSample {
    align-self: center;
    width: fit-content;
    max-width: min(100%, 19rem);
    text-align: center;
    justify-content: center;
  }

  .page-scroll {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .page-nav {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .page-nav-center {
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
    max-width: 100%;
    min-width: 0;
  }

  .page-nav-btn-text {
    display: none;
  }

  .page-nav-btn-icon {
    display: inline;
    font-size: 1.05rem;
    line-height: 1;
  }

  .page-nav-btn {
    padding: 0.42rem 0.55rem;
    min-width: 2.35rem;
  }

  #pageIndicator {
    flex: 1 1 auto;
    min-width: 0;
    text-align: center;
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #btnPrev {
    margin-right: 0;
    flex-shrink: 0;
  }

  #btnNext {
    margin-left: 0;
    flex-shrink: 0;
  }

  .app-version {
    display: none;
  }
}
