/* Bento hybrid mock — оболочка из плиток, текст одной спокойной поверхностью */

:root {
  --bento-bg: #eceef3;
  --bento-bg-glow: radial-gradient(900px 480px at 12% 0%, rgba(120, 82, 238, 0.1), transparent 60%),
    radial-gradient(700px 420px at 90% 10%, rgba(90, 120, 200, 0.08), transparent 55%);
  --bento-tile: #f7f8fb;
  --bento-tile-strong: #ffffff;
  --bento-tile-muted: #f0f2f7;
  --bento-border: rgba(28, 30, 40, 0.06);
  --bento-shadow: 0 1px 2px rgba(28, 30, 40, 0.04), 0 8px 24px rgba(28, 30, 40, 0.05);
  --bento-radius: 22px;
  --bento-radius-sm: 14px;
  --bento-gap: 14px;
  --bento-accent: #7852ee;
  --bento-accent-soft: rgba(120, 82, 238, 0.12);
  --bento-accent-strong: #6340d8;
  --bento-text: #1a1c23;
  --bento-text-muted: #5c6370;
  --bento-btn: 36px;
  --bento-gutter: 14px;

  --color-primary: var(--bento-accent);
  --color-primary-hover: var(--bento-accent-strong);
  --color-link: var(--bento-accent);
  --color-link-hover: var(--bento-accent-strong);
  --color-blockquote-border: var(--bento-accent);
  --color-text: var(--bento-text);
  --color-text-secondary: var(--bento-text-muted);
  --font-family: Inter, "Helvetica Neue", sans-serif;
  --font-family-mono: "JetBrains Mono", "Roboto Mono", ui-monospace, monospace;
  --content-max-width: 720px;
  --z-theme-toggle: 1000;
}

body.dark-theme {
  --bento-bg: #12141a;
  --bento-bg-glow: radial-gradient(900px 480px at 10% 0%, rgba(168, 130, 255, 0.12), transparent 55%),
    radial-gradient(700px 420px at 92% 8%, rgba(80, 100, 180, 0.08), transparent 50%);
  --bento-tile: #1a1d26;
  --bento-tile-strong: #20242f;
  --bento-tile-muted: #161922;
  --bento-border: rgba(255, 255, 255, 0.07);
  --bento-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 10px 28px rgba(0, 0, 0, 0.28);
  --bento-accent: #a882ff;
  --bento-accent-soft: rgba(168, 130, 255, 0.16);
  --bento-accent-strong: #c0a4ff;
  --bento-text: #e8eaf0;
  --bento-text-muted: #9aa1b0;

  --color-primary: var(--bento-accent);
  --color-primary-hover: var(--bento-accent-strong);
  --color-link: var(--bento-accent);
  --color-link-hover: var(--bento-accent-strong);
  --color-blockquote-border: var(--bento-accent);
  --color-text: var(--bento-text);
  --color-text-secondary: var(--bento-text-muted);
}

html {
  min-height: 100%;
  scrollbar-gutter: stable;
}

body {
  margin: 0; /* иначе modal-open сбрасывает дефолтные 8px и страница «прыгает» */
  color: var(--bento-text);
  background-color: var(--bento-bg);
  background-image: var(--bento-bg-glow);
  background-attachment: fixed;
  font-family: var(--font-family);
  overflow-x: clip;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* Прогресс — тонкая линия по верху, без панели */
.reading-progress {
  height: 2px;
  background: transparent;
}

.reading-progress-bar {
  background: linear-gradient(90deg, var(--bento-accent), #9b7cff);
  border-radius: 0 2px 2px 0;
}

/* Actions: одна компактная bento-плитка слева, внутри — лёгкие кнопки */
.controls-container {
  top: var(--bento-gap);
  left: var(--bento-gap);
  right: auto;
  width: auto;
  max-width: calc(100vw - 28px);
  padding: 8px;
  gap: 4px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-start;
  background: var(--bento-tile) !important;
  border: 1px solid var(--bento-border);
  border-radius: var(--bento-radius);
  box-shadow: none;
  pointer-events: auto;
}

body.dark-theme .controls-container {
  background: var(--bento-tile) !important;
}

.icon-btn {
  width: var(--bento-btn);
  height: var(--bento-btn);
  padding: 0;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--bento-text-muted);
  box-shadow: none;
  display: grid;
  place-items: center;
  line-height: 0;
  font-size: 0;
  font-style: normal;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

body.dark-theme .icon-btn {
  background: transparent;
  color: var(--bento-text-muted);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--bento-accent);
  outline-offset: 2px;
}

.icon-btn:active {
  background: var(--bento-accent-soft);
  color: var(--bento-accent);
}

@media (hover: hover) {
  .icon-btn:hover {
    transform: none;
    background: var(--bento-accent-soft);
    color: var(--bento-accent);
  }
}

.icon-btn > i,
.icon-btn > svg {
  grid-area: 1 / 1;
  display: block;
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  position: static;
  inset: auto;
  transform: none;
  line-height: 0;
  font-size: 0;
  font-style: normal;
  opacity: 1;
  color: inherit;
}

.theme-toggle,
.theme-toggle:active {
  animation: none;
}

.theme-toggle .ph,
.theme-toggle .sun-icon,
.theme-toggle .moon-icon {
  position: static;
  opacity: 1;
  color: inherit;
}

/* Две иконки темы: показываем только актуальную (style.css гасит их через opacity) */
.theme-toggle .moon-icon,
body.dark-theme .theme-toggle .sun-icon {
  display: none;
}

body.dark-theme .theme-toggle .moon-icon {
  display: block;
}

.icon-btn svg,
.toc-visibility-toggle svg,
.close-modal svg,
.scroll-to-top svg,
.table-expand-toggle svg,
.copy-button svg,
.wrap-toggle-button svg,
.external-link-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  flex-shrink: 0;
  display: block;
}

.external-link-icon,
.external-link-icon svg {
  width: 14px;
  height: 14px;
}

.external-link-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: baseline;
}

.toc-toggle {
  display: flex;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0;
}

.search-container-inline {
  position: static;
  left: auto;
  top: auto;
  z-index: auto;
  width: 0;
  min-width: 0;
  flex: 0 0 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  border: none;
  border-radius: 10px;
  background: transparent;
  box-shadow: none;
  white-space: nowrap;
  pointer-events: none;
  transition: width 0.2s ease, opacity 0.2s ease, visibility 0.2s ease, margin 0.2s ease;
}

body.dark-theme .search-container-inline {
  background: transparent;
  box-shadow: none;
}

.search-container-inline.active {
  width: 220px;
  flex: 0 0 220px;
  margin-left: 4px;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.search-input-inline {
  width: 100%;
  height: var(--bento-btn);
  padding: 0 12px;
  border: 1px solid var(--bento-border);
  border-radius: 10px;
  background: var(--bento-tile-muted);
  color: var(--bento-text);
  font-family: var(--font-family);
  font-size: 13px;
  box-shadow: none;
  box-sizing: border-box;
}

.search-input-inline::placeholder {
  color: var(--bento-text-muted);
}

.search-input-inline:focus {
  outline: none;
  background: var(--bento-tile-muted);
  box-shadow: none;
  border-color: color-mix(in srgb, var(--bento-accent) 45%, var(--bento-border));
}

body.dark-theme .search-input-inline,
body.dark-theme .search-input-inline:focus {
  background: var(--bento-tile-muted);
  color: var(--bento-text);
}

.search-wrapper:has(.search-container-inline.active) .search-toggle {
  background: var(--bento-accent-soft);
  color: var(--bento-accent);
}

.search-highlighted {
  background-color: var(--bento-accent-soft) !important;
  border-radius: 6px;
  padding: 0.2em 0.6em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  outline: none !important;
  box-shadow: none !important;
}

.search-highlighted.search-current {
  background-color: color-mix(in srgb, var(--bento-accent) 16%, transparent) !important;
  outline: none !important;
  box-shadow: none !important;
}

body.dark-theme .search-highlighted {
  background-color: var(--bento-accent-soft) !important;
}

body.dark-theme .search-highlighted.search-current {
  background-color: color-mix(in srgb, var(--bento-accent) 20%, transparent) !important;
  outline: none !important;
}

/* TOC — та же bento-плитка, что и панель действий */
.toc {
  top: var(--bento-gap);
  right: var(--bento-gap);
  width: 244px;
  min-width: 244px;
  max-width: 244px;
  max-height: calc(100vh - 28px);
  padding: 8px;
  border-radius: var(--bento-radius);
  border: 1px solid var(--bento-border);
  background: var(--bento-tile);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

body.dark-theme .toc {
  background: var(--bento-tile);
}

.toc.collapsed {
  width: 244px;
  min-width: 244px;
  max-width: 244px;
  max-height: none;
  height: auto;
  padding: 8px;
  overflow: hidden;
  display: block;
  transform: none;
  cursor: default; /* плитка не кликабельна, указатель только на кнопке */
}

.toc-title {
  cursor: default;
}

.toc-visibility-toggle {
  cursor: pointer;
}

.toc.collapsed:hover,
body.dark-theme .toc.collapsed:hover {
  background: var(--bento-tile);
}

.toc.collapsed ul {
  display: none;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
}

.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-height: var(--bento-btn);
  margin: 0 0 4px;
  padding: 0 8px 0 10px;
  border-bottom: none;
}

body.dark-theme .toc-header {
  border-bottom: none;
}

.toc.collapsed .toc-header {
  margin: 0;
  padding: 0 8px 0 10px;
  min-height: var(--bento-btn);
  justify-content: space-between;
}

.toc.collapsed .toc-title {
  display: block;
}

.toc-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--bento-text-muted);
  flex: 1;
}

.toc-visibility-toggle {
  width: var(--bento-btn);
  height: var(--bento-btn);
  margin: 0;
  padding: 0;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--bento-text-muted);
  display: grid;
  place-items: center;
  line-height: 0;
  font-size: 0;
}

.toc-visibility-toggle:hover,
body.dark-theme .toc-visibility-toggle:hover {
  background: var(--bento-accent-soft);
  color: var(--bento-accent);
}

.toc-visibility-toggle i,
.toc-visibility-toggle svg {
  display: block;
  width: 18px;
  height: 18px;
  margin: 0;
  stroke: currentColor;
}

.toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toc li {
  margin: 0;
  line-height: 1.35;
}

.toc li:has(> a.toc-h2 + ul) {
  margin: 0;
}

.toc li > a.toc-h2 + ul {
  margin-top: 2px;
}

.toc a {
  display: block;
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--bento-text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  transition: background 0.15s ease, color 0.15s ease;
}

.toc a:hover {
  background: var(--bento-tile-muted);
  color: var(--bento-text);
}

.toc a.active {
  background: var(--bento-accent-soft);
  color: var(--bento-accent);
  font-weight: 600;
}

.toc a.active::before {
  display: none;
}

.toc .toc-h2 {
  padding-left: 10px;
  font-weight: 500;
}

.toc .toc-h3 {
  padding-left: 22px;
  font-size: 13px;
  font-weight: 400;
}

.toc .toc-h4 { padding-left: 34px; }
.toc .toc-h5 { padding-left: 46px; }
.toc .toc-h6 { padding-left: 58px; }

/* Главная плитка заметки — одна поверхность для чтения */
.content {
  margin: var(--bento-gap) auto 12px;
  padding: 28px;
  border-radius: calc(var(--bento-radius) + 4px);
  border: 1px solid var(--bento-border);
  background: var(--bento-tile-strong);
  box-shadow: none;
  box-sizing: border-box;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

body.dark-theme .content {
  background: var(--bento-tile-strong);
}

#main {
  opacity: 1 !important;
  transform: none !important;
  padding-top: 0;
}

#main h1 {
  font-weight: 650;
  font-size: 1.85rem;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin: 0 0 0.35em;
  color: var(--bento-text);
}

#main h2 {
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  margin: 1.15em 0 0.35em;
  color: var(--bento-text);
}

#main h3 {
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  margin: 0.9em 0 0.3em;
  color: var(--bento-text);
}

#main p {
  margin: 0 0 0.7em;
  color: var(--bento-text);
  line-height: 1.55;
}

#main li {
  color: var(--bento-text);
  line-height: 1.55;
}

#main ul,
#main ol {
  margin: 0 0 0.7em;
  padding-left: 1.35em;
}

#main code {
  font-family: var(--font-family-mono);
  background: var(--bento-tile-muted);
  color: var(--bento-text);
  padding: 0.12em 0.4em;
  border-radius: 6px;
  font-size: 0.88em;
}

#main pre {
  border-radius: var(--bento-radius-sm);
  border: 1px solid var(--bento-border);
  background: var(--bento-tile-muted) !important;
  box-shadow: none;
  padding: 16px 18px;
}

#main pre code {
  display: block;
  padding: 0;
  background: transparent;
  border-radius: 0;
  font-size: 0.88em;
}

body.dark-theme #main pre {
  background: var(--bento-tile-muted) !important;
  border-color: var(--bento-border);
}

#main blockquote {
  border-left: 3px solid var(--bento-accent);
  padding: 4px 0 4px 16px;
  color: var(--bento-text-muted);
  background: transparent;
  border-radius: 0;
}

#main hr,
#main .footnotes-sep {
  display: block;
  width: auto;
  height: 1px;
  margin: 1.85em 0 1.5em;
  padding: 0;
  border: none;
  background: var(--bento-border);
}

#main .footnotes {
  color: var(--bento-text-muted);
  font-size: 0.92em;
}

#main .footnotes-list {
  margin: 0;
  padding-left: 1.35em;
}

#main .footnote-backref {
  color: var(--bento-text-muted);
  text-decoration: none;
}

#main .footnote-backref:hover {
  color: var(--bento-accent);
}

#main .header-anchor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.95em;
  height: 0.95em;
  margin-left: 0.35em;
  vertical-align: -0.08em;
  color: var(--bento-text-muted);
  text-decoration: none;
  opacity: 0;
  transform: none;
  transition: opacity 0.15s ease, color 0.15s ease;
}

#main h1:hover .header-anchor,
#main h2:hover .header-anchor,
#main h3:hover .header-anchor,
#main h4:hover .header-anchor,
#main h5:hover .header-anchor,
#main h6:hover .header-anchor,
#main .header-anchor:focus,
#main .header-anchor:focus-visible {
  visibility: visible;
  opacity: 0.45;
  transform: none;
  color: var(--bento-text-muted);
}

#main .header-anchor:hover,
#main .header-anchor:focus-visible {
  opacity: 1;
  color: var(--bento-text);
}

#main .header-anchor.is-copied,
#main .header-anchor.is-copied:hover {
  opacity: 1;
  color: var(--bento-text);
  transform: none;
}

#main .header-anchor svg {
  width: 0.85em;
  height: 0.85em;
  display: block;
  stroke: currentColor;
}

a {
  color: var(--bento-accent);
}

a:hover,
a:focus-visible {
  color: var(--bento-accent-strong);
}

.external-link-icon {
  color: var(--bento-accent);
}

/* Мета — тихая строка под контейнером заметки */
#footer {
  display: block;
  box-sizing: border-box;
  max-width: var(--content-max-width);
  margin: 8px auto 48px;
  padding: 0 28px;
  border-top: none;
  color: var(--bento-text-muted);
}

#footer .file-metadata {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 6px;
}

#footer .metadata-item {
  display: inline-flex;
  flex-direction: row;
  flex: 0 0 auto;
  width: auto;
  align-items: baseline;
  gap: 6px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
}

#footer .metadata-item:not([hidden]) + .metadata-item:not([hidden])::before {
  content: "·";
  color: var(--bento-text-muted);
  opacity: 0.6;
}

.metadata-label {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--bento-text-muted);
  min-width: 0;
}

.metadata-label::after {
  content: ":";
}

.metadata-item time {
  color: var(--bento-text-muted);
  font-size: 12px;
}

#footer .metadata-item[hidden] {
  display: none !important;
}

.footer-history-toggle {
  font-size: 12px;
  color: var(--bento-text-muted);
}

.footer-history-toggle:hover,
.footer-history-toggle[aria-expanded="true"] {
  color: var(--bento-accent);
}

body.dark-theme #footer {
  border-top: none;
}

.markdown-table {
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border-radius: var(--bento-radius-sm);
  border: 1px solid var(--bento-border);
  box-shadow: none;
}

.markdown-table th {
  background: var(--bento-tile-muted) !important;
  color: var(--bento-text);
  font-weight: 600;
}

.markdown-table td,
.markdown-table th {
  border-color: var(--bento-border) !important;
}

.markdown-table tr:nth-child(even) {
  background: color-mix(in srgb, var(--bento-tile-muted) 55%, transparent);
}

.markdown-table tr:hover {
  background: var(--bento-accent-soft);
}

body.dark-theme .markdown-table {
  border-color: var(--bento-border);
  box-shadow: none;
}

.img-wrapper {
  position: relative;
  margin: 0.7em 0 1em;
  padding: 0;
  border: none;
  border-radius: 0;
  overflow: visible;
  background: transparent;
  box-shadow: none;
  text-align: center;
}

.img-wrapper img {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0;
  border-radius: var(--bento-radius-sm);
  box-shadow: none;
}

.img-wrapper .img-zoomable {
  cursor: zoom-in;
  transform: none;
  box-shadow: none;
  transition: filter 0.2s ease;
}

.img-zoomable:hover {
  transform: none;
  box-shadow: none;
  filter: brightness(0.58);
}

.img-zoomable:active {
  transform: none;
}

.img-caption {
  margin: 8px 0 0;
  padding: 0;
  color: var(--bento-text-muted);
  font-size: 0.875rem;
  background: transparent;
}

/* Просмотрщик картинок из index.js: тот же .modal-overlay, но тёмный фон и плоские кнопки */
.modal-overlay:has(.modal-image) {
  background: rgba(10, 12, 18, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.modal-image {
  border-radius: 12px;
  box-shadow: none;
}

.modal-close-btn,
.modal-nav-btn {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 0;
  line-height: 0;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-close-btn:hover,
.modal-nav-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: none;
}

.modal-nav-btn:hover {
  transform: translateY(-50%);
}

.modal-close-btn svg,
.modal-nav-btn svg {
  width: 20px;
  height: 20px;
  display: block;
  stroke: currentColor;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  place-items: center;
  padding: 28px;
  background: rgba(10, 12, 18, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: zoom-out;
}

.lightbox-overlay.is-open {
  display: grid;
}

.lightbox-image {
  max-width: min(92vw, 1200px);
  max-height: 90vh;
  width: auto;
  height: auto;
  margin: 0;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: none;
  opacity: 1;
  animation: none;
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: var(--bento-btn);
  height: var(--bento-btn);
  padding: 0;
  border: 1px solid var(--bento-border);
  border-radius: 10px;
  background: var(--bento-tile);
  color: var(--bento-text);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.lightbox-close svg {
  width: 18px;
  height: 18px;
  display: block;
  stroke: currentColor;
}

input[type="checkbox"] {
  border-radius: 5px;
  border-color: var(--bento-text-muted);
  accent-color: var(--bento-accent);
}

input[type="checkbox"]:checked {
  /* Галочка — фоном самого чекбокса, по центру; ::after из style.css отключён */
  background-color: var(--bento-accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 72% 72%;
  border-color: var(--bento-accent);
}

input[type="checkbox"]:checked::after,
body.dark-theme input[type="checkbox"]:checked::after {
  content: none;
  display: none;
}

input[type="checkbox"]:checked:hover,
input[type="checkbox"]:checked:focus-visible {
  background-color: var(--bento-accent-strong);
  border-color: var(--bento-accent-strong);
}

/* Блокировка прокрутки без смены ширины страницы: полоса прокрутки не исчезает */
html.modal-open,
body.modal-open {
  position: static !important;
  width: auto !important;
  height: auto !important;
  top: auto !important;
  bottom: auto !important;
}

html.modal-open {
  overflow: hidden !important;
  scrollbar-gutter: stable;
}

body.modal-open {
  overflow: visible !important;
}

/* Модалки — та же плитка, что тулбар и TOC */
.modal-overlay {
  touch-action: auto;
  background: color-mix(in srgb, var(--bento-bg) 45%, rgba(18, 20, 28, 0.22));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

body.dark-theme .modal-overlay {
  background: rgba(8, 10, 16, 0.55);
}

.modal-content {
  box-sizing: border-box;
  width: min(360px, calc(100vw - 28px));
  max-width: 360px;
  padding: 8px 8px 10px;
  border-radius: var(--bento-radius);
  border: 1px solid var(--bento-border);
  background: var(--bento-tile);
  box-shadow: none;
  color: var(--bento-text);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  transform: none;
}

.modal-overlay[aria-hidden="false"] .modal-content {
  transform: none;
}

body.dark-theme .modal-content {
  background: var(--bento-tile);
  border-color: var(--bento-border);
}

.modal-header {
  margin: 0 0 4px;
  padding: 0 6px 0 10px;
  min-height: var(--bento-btn);
  border-bottom: none;
}

.modal-header h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--bento-text-muted);
}

.close-modal {
  width: var(--bento-btn);
  height: var(--bento-btn);
  padding: 0;
  border-radius: 10px;
  font-size: 0;
  line-height: 0;
  color: var(--bento-text-muted);
  display: grid;
  place-items: center;
}

.close-modal:hover {
  background: var(--bento-accent-soft);
  color: var(--bento-accent);
}

.close-modal svg {
  width: 18px;
  height: 18px;
  display: block;
  stroke: currentColor;
}

.history-list {
  margin-bottom: 4px;
}

.history-item {
  border: none;
  border-radius: 12px;
  border-bottom: none;
  padding: 10px 12px;
}

.history-item + .history-item {
  margin-top: 2px;
}

.history-item:hover {
  background: var(--bento-tile-muted);
  border-color: transparent;
  color: var(--bento-text);
}

.history-item:hover .title {
  color: var(--bento-accent);
}

.history-item .title {
  color: var(--bento-text);
  font-weight: 500;
  font-size: 14px;
}

.history-item .date {
  color: var(--bento-text-muted);
  font-size: 12px;
}

.history-list .empty-message {
  color: var(--bento-text-muted);
}

.modal-footer {
  text-align: right;
  border-top: none;
  padding: 2px 10px 4px;
}

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--bento-text-muted);
  text-decoration: none;
}

.text-btn i {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin: 0;
  font-size: 0;
  line-height: 0;
}

.text-btn svg {
  display: block;
  width: 16px;
  height: 16px;
  stroke: currentColor;
  flex-shrink: 0;
}

.text-btn:hover {
  color: var(--bento-accent);
}

.scroll-to-top {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--bento-border);
  background: var(--bento-tile);
  color: var(--bento-text-muted);
  box-shadow: var(--bento-shadow);
  font-size: 18px;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.scroll-to-top:hover {
  background: var(--bento-tile-strong);
  color: var(--bento-accent);
  transform: translateY(-1px);
  box-shadow: var(--bento-shadow);
}

body.dark-theme .scroll-to-top,
body.dark-theme .scroll-to-top:hover {
  background: var(--bento-tile);
  box-shadow: var(--bento-shadow);
}

.notification {
  bottom: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--bento-border);
  background: var(--bento-tile);
  color: var(--bento-text);
  box-shadow: none;
  font-family: var(--font-family);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  max-width: min(320px, calc(100vw - 40px));
}

body.dark-theme .notification {
  background: var(--bento-tile);
  border-color: var(--bento-border);
  color: var(--bento-text);
}

.notification-success,
.notification-error {
  border-left: 1px solid var(--bento-border);
}

.notification svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: block;
  stroke: currentColor;
}

.notification-success {
  color: var(--bento-text);
}

.notification-success svg {
  color: var(--bento-accent);
}

.notification-error {
  background: color-mix(in srgb, #e85d4c 10%, var(--bento-tile));
  border-color: color-mix(in srgb, #e85d4c 28%, var(--bento-border));
}

.notification-error svg {
  color: #e85d4c;
}

.copy-button,
.wrap-toggle-button,
.table-expand-toggle button {
  border-radius: 10px !important;
  background: var(--bento-tile-strong) !important;
  color: var(--bento-text-muted) !important;
  border: 1px solid var(--bento-border) !important;
}

/* Широкий экран: контент всегда по центру; TOC поверх/в поле справа */
@media (min-width: 1200px) {
  .content {
    margin-left: auto;
    margin-right: auto;
  }
}

/* До 1200px боковая плитка TOC скрыта в любом состоянии (в т.ч. свёрнутом), оглавление — в модалке */
@media (max-width: 1200px) {
  .toc,
  .toc.collapsed {
    display: none !important;
  }
}

/* Оглавление в модалке — тот же ритм, что у «Недавних» */
#toc-modal-content .toc-header {
  display: none;
}

#toc-modal-content ul,
#toc-modal-content li > ul,
#toc-modal-content li > a.toc-h2 + ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

#toc-modal-content li,
#toc-modal-content li:has(> a.toc-h2 + ul) {
  margin: 0;
}

#toc-modal-content li + li,
#toc-modal-content li > ul {
  margin-top: 2px;
}

#toc-modal-content a,
#toc-modal-content .toc-h2 {
  display: flex;
  align-items: center;
  min-height: 0;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--bento-text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
}

#toc-modal-content .toc-h3,
#toc-modal-content .toc-h4,
#toc-modal-content .toc-h5,
#toc-modal-content .toc-h6 {
  font-size: 13px;
  font-weight: 400;
}

#toc-modal-content .toc-h3 { padding-left: 24px; }
#toc-modal-content .toc-h4 { padding-left: 36px; }
#toc-modal-content .toc-h5 { padding-left: 48px; }
#toc-modal-content .toc-h6 { padding-left: 60px; }

#toc-modal-content a:hover {
  background: var(--bento-tile-muted);
  color: var(--bento-text);
}

#toc-modal-content a.active {
  color: var(--bento-accent);
  background: var(--bento-accent-soft);
}

#toc-modal .modal-content {
  max-height: min(78vh, 640px);
  overflow-y: auto;
}

@media (max-width: 768px) {
  body {
    background-attachment: scroll;
    --bento-gutter: 10px;
  }

  .controls-container {
    position: sticky;
    top: calc(var(--bento-gutter) + env(safe-area-inset-top, 0px));
    left: auto;
    right: auto;
    width: auto;
    max-width: none;
    margin: calc(var(--bento-gutter) + env(safe-area-inset-top, 0px)) var(--bento-gutter) 0;
    padding: 6px;
    gap: 4px;
    border-radius: 18px;
    justify-content: flex-start;
    box-sizing: border-box;
    flex-wrap: nowrap;
  }

  .toc-toggle {
    order: 999;
    margin-left: auto;
    display: flex !important;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
  }

  .search-wrapper {
    flex: 0 0 auto;
    min-width: 0;
  }

  .controls-container:has(.search-container-inline.active) .search-wrapper {
    flex: 1 1 0;
    min-width: 0;
  }

  .search-container-inline.active {
    width: auto;
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
  }

  .search-input-inline {
    font-size: 16px; /* меньше — iOS зумит страницу при фокусе */
    min-width: 0;
    height: 44px;
  }

  .search-input-inline::placeholder {
    font-size: 14px;
  }

  .content {
    margin: var(--bento-gutter) var(--bento-gutter) var(--bento-gutter);
    padding: 20px 18px;
    border-radius: 18px;
    max-width: none;
    width: auto;
  }

  /* Мета на мобилке — короткий столбик, без точек-разделителей; справа место под кнопку «Наверх» */
  #footer {
    margin: 4px var(--bento-gutter) calc(28px + env(safe-area-inset-bottom, 0px));
    padding: 0 72px 0 18px;
    max-width: none;
  }

  #footer .file-metadata {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 4px;
  }

  #footer .metadata-item:not([hidden]) + .metadata-item:not([hidden])::before {
    content: none;
  }

  #footer .metadata-item {
    gap: 5px;
    line-height: 1.4;
  }

  .metadata-label,
  .metadata-item time {
    font-size: 13px;
  }

  #footer .footer-history-item {
    margin-top: 6px;
  }

  .footer-history-toggle {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    font-size: 13px;
    font-weight: 500;
    color: var(--bento-accent);
  }

  #main {
    padding-top: 0;
  }

  #main h1 {
    font-size: 1.55rem;
  }

  #main h2 {
    font-size: 1.15rem;
  }

  #main .header-anchor {
    opacity: 0.4;
  }

  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #toc-modal {
    align-items: center;
    justify-content: center;
    padding: calc(var(--bento-gutter) + env(safe-area-inset-top, 0px)) var(--bento-gutter) calc(var(--bento-gutter) + env(safe-area-inset-bottom, 0px));
  }

  #toc-modal .modal-content {
    width: min(calc(100vw - 20px), 360px);
    max-width: none;
    margin: 0;
    border-radius: 18px;
    padding: 8px 8px 10px;
    transform: none;
  }

  #history-modal .modal-content {
    width: min(calc(100vw - 20px), 360px);
    max-width: none;
  }

  .scroll-to-top {
    right: 12px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .notification {
    left: 12px;
    right: 12px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    max-width: none;
  }

  .lightbox-overlay {
    padding: 16px;
  }

  .lightbox-close {
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: 12px;
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 480px) {
  .content {
    padding: 18px 16px;
    font-size: inherit;
  }

  #main {
    padding-top: 0;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }
}

/* Скелетон загрузки заметки */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skeleton {
  display: grid;
  gap: 12px;
  padding: 6px 0 10px;
  /* задержка: при быстрой загрузке скелетон не успевает показаться */
  animation: skeleton-appear 0.2s ease-out 0.15s both;
}

.skeleton-line {
  height: 14px;
  width: var(--w, 100%);
  border-radius: 7px;
  background: linear-gradient(
    90deg,
    var(--bento-tile-muted) 0%,
    color-mix(in srgb, var(--bento-tile-muted) 55%, var(--bento-tile-strong)) 50%,
    var(--bento-tile-muted) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.6s ease-in-out infinite;
}

.skeleton-title {
  height: 30px;
  width: 58%;
  border-radius: 10px;
  margin-bottom: 8px;
}

.skeleton-heading {
  height: 20px;
  width: 36%;
  border-radius: 8px;
  margin-top: 14px;
}

.skeleton-block {
  height: 92px;
  width: 100%;
  border-radius: var(--bento-radius-sm);
  margin: 6px 0;
}

body.dark-theme .skeleton-line {
  background-image: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.06) 0%,
    rgba(255, 255, 255, 0.12) 50%,
    rgba(255, 255, 255, 0.06) 100%
  );
}

@keyframes skeleton-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@keyframes skeleton-appear {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 768px) {
  .skeleton-title { width: 74%; height: 26px; }
  .skeleton-heading { width: 48%; }
  .skeleton-block { height: 76px; }
}

@media (prefers-reduced-motion: reduce) {
  .icon-btn,
  .scroll-to-top,
  .toc a,
  .history-item,
  body {
    transition: none;
  }

  .skeleton {
    animation-duration: 0.01ms;
    animation-delay: 0s;
  }

  .skeleton-line {
    animation: none;
    background-size: 100% 100%;
  }
}
