:root {
  color-scheme: dark;
  --bg: #000;
  --fg: #fff;
  --muted: #9a9a9a;
  --line: #2a2a2a;
  --panel: #080808;
  --panel-strong: #0d0d0d;
  --navy: #071a35;
  --navy-soft: #0b254a;
  --navy-line: #1d4f86;
  --toolbar-border: rgba(255, 255, 255, 0.75);
  --focus: #fff;
  --ok: #baffd1;
  --warn: #ffe7a3;
  --accent: #c8ddff;
  --soft-radius: 7px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: Inter, Arial, sans-serif;
  font-weight: 400;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.topbar,
.toolbar,
.result,
.pane > span,
.pane-head,
.modal-panel,
.tooltip {
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
}

.topbar {
  min-height: 64px;
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: linear-gradient(180deg, var(--navy), #000 72%);
}

.brand {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.title-input {
  width: 100%;
  min-width: 0;
  padding: 10px 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 4px 4px 0 0;
  color: var(--fg);
  outline: none;
}

.title-input:focus {
  border-color: var(--focus);
}

.actions,
.pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar {
  min-height: 48px;
  padding: 8px 18px;
  overflow-x: auto;
  background: linear-gradient(90deg, #030303, var(--navy) 50%, #030303);
  scrollbar-width: thin;
  display: flex;
  align-items: stretch;
  gap: 10px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--soft-radius);
  background: rgba(5, 5, 5, 0.92);
  flex: 0 0 auto;
  scroll-snap-align: start;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.tool-group:hover {
  border-color: var(--navy-line);
  background: rgba(7, 26, 53, 0.72);
}

.tool-group > span {
  color: var(--muted);
  font-size: 11px;
  padding: 0 4px;
  white-space: nowrap;
}

.toolbar button,
.toolbar-upload,
.icon-button,
.primary-button,
.history-select {
  min-height: 32px;
  border: 1px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
  padding: 6px 10px;
  border-radius: var(--soft-radius);
  cursor: pointer;
  font-weight: 500;
  text-transform: uppercase;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.toolbar button,
.toolbar-upload {
  border-color: var(--toolbar-border);
}

.toolbar button,
.toolbar-upload {
  height: 42px;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  white-space: nowrap;
}

.toolbar button,
.toolbar-upload,
.toolbar-upload span,
.quick-add button,
.empty-editor button,
.block-card-head strong,
.format-bar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.ui-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  object-fit: contain;
  filter: brightness(0) invert(1);
  pointer-events: none;
  transition: filter 140ms ease;
}

.tool-group > span .ui-icon {
  width: 16px;
  height: 16px;
}

.toolbar button:hover,
.toolbar-upload:hover,
.icon-button:hover,
.primary-button:hover,
.history-select:hover {
  background: var(--fg);
  color: var(--bg);
  transform: translateY(-1px);
  box-shadow: 0 0 0 2px rgba(29, 79, 134, 0.42);
}

.toolbar button:hover .ui-icon,
.toolbar-upload:hover .ui-icon,
.primary-button:hover .ui-icon,
.quick-add button:hover .ui-icon,
.empty-editor button:hover .ui-icon,
.format-bar button:hover .ui-icon,
.format-bar button:focus-visible .ui-icon {
  filter: brightness(0);
}

.toolbar button:focus-visible,
.toolbar-upload:focus-visible,
.icon-button:focus-visible,
.primary-button:focus-visible,
.history-select:focus-visible,
.title-input:focus-visible,
textarea:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 2px;
}

.history-select {
  max-width: 190px;
}

.icon-button input {
  display: none;
}

.toolbar-upload input {
  display: none;
}

.primary-button {
  background: var(--fg);
  color: var(--bg);
  font-weight: 600;
}

.primary-button:hover {
  background: var(--bg);
  color: var(--fg);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(380px, 0.95fr) minmax(360px, 1.05fr);
  background: #050505;
}

.pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border-right: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--soft-radius) var(--soft-radius) 0 0;
  overflow: hidden;
}

.pane > span,
.pane-head {
  min-height: 42px;
  padding: 12px 14px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.editor-head {
  gap: 12px;
}

.editor-hints {
  display: flex;
  gap: 5px;
  flex: 1;
  min-width: 140px;
  overflow-x: auto;
  scrollbar-width: none;
}

.editor-hints span {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #020202;
  color: var(--muted);
  padding: 4px 6px;
  font-size: 10px;
  white-space: nowrap;
}

.mode-switch {
  display: flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--soft-radius);
  background: #000;
}

.mode-switch button {
  min-height: 28px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  padding: 4px 9px;
  cursor: pointer;
  text-transform: uppercase;
}

.mode-switch button.active {
  background: var(--navy-soft);
  color: var(--fg);
}

.block-editor {
  min-height: 0;
  height: 100%;
  padding: 14px;
  overflow: auto;
  background:
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.05), transparent 28%),
    #050505;
  scrollbar-width: thin;
}

.editor-wrap {
  display: none;
}

.raw-mode .block-editor {
  display: none;
}

.raw-mode .editor-wrap {
  display: block;
}

.block-card {
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--soft-radius);
  background: #0a0a0a;
  overflow: hidden;
  position: relative;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.block-card:hover,
.block-card:focus-within,
.block-card.is-active {
  border-color: var(--navy-line);
  background: #0d1119;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(29, 79, 134, 0.28) inset;
  transform: translateY(-1px);
}

.block-card.is-active {
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.34), 0 0 0 2px rgba(29, 79, 134, 0.42) inset;
}

.block-card.is-dragging {
  opacity: 0.55;
  transform: scale(0.985);
}

.block-card.is-collapsed .block-fields,
.block-card.is-collapsed .block-raw,
.block-card.is-collapsed .quick-add {
  display: none;
}

.block-card.is-collapsed .block-summary {
  padding-bottom: 10px;
}

.block-card.drop-before::before,
.block-card.drop-after::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  height: 4px;
  border-radius: 0;
  background: var(--navy-line);
  box-shadow: 0 0 0 2px rgba(29, 79, 134, 0.2), 0 0 18px rgba(29, 79, 134, 0.85);
  z-index: 4;
}

.block-card.drop-before::before {
  top: 0;
}

.block-card.drop-after::after {
  bottom: 0;
}

.block-card-head {
  min-height: 42px;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #000;
}

.block-kind {
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  padding: 3px 6px;
  font-size: 10px;
  text-transform: uppercase;
}

.group-text {
  border-color: rgba(255, 255, 255, 0.18);
}

.group-media {
  border-color: rgba(255, 128, 191, 0.45);
}

.group-structure {
  border-color: rgba(255, 214, 102, 0.45);
}

.group-telegram {
  border-color: rgba(29, 79, 134, 0.9);
}

.group-text .block-card-head {
  background: linear-gradient(90deg, rgba(255,255,255,0.06), #000);
}

.group-media .block-card-head {
  background: linear-gradient(90deg, rgba(255,128,191,0.13), #000);
}

.group-structure .block-card-head {
  background: linear-gradient(90deg, rgba(255,214,102,0.12), #000);
}

.group-telegram .block-card-head {
  background: linear-gradient(90deg, var(--navy-soft), #000);
}

.drag-handle {
  color: var(--muted);
  cursor: grab;
  font-weight: 700;
  user-select: none;
  touch-action: none;
  padding: 4px 6px;
  border-radius: 5px;
  transition: background 140ms ease, color 140ms ease;
}

.drag-handle:hover {
  background: var(--navy-soft);
  color: var(--fg);
}

.drag-handle:active {
  cursor: grabbing;
}

.block-card-head strong {
  font-size: 12px;
  text-transform: uppercase;
}

.block-summary {
  padding: 8px 10px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  text-transform: none;
}

.block-actions {
  display: flex;
  gap: 4px;
}

.block-actions button {
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #050505;
  color: var(--fg);
  font-size: 10px;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.block-actions button:hover:not(:disabled) {
  background: var(--navy-soft);
  border-color: var(--navy-line);
}

.block-actions button:disabled {
  opacity: 0.35;
  cursor: default;
}

.block-fields {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.block-fields input,
.block-fields select,
.block-fields textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--soft-radius);
  background: #020202;
  color: var(--fg);
  padding: 10px;
  outline: none;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.block-fields textarea {
  min-height: 84px;
  resize: vertical;
  line-height: 1.45;
}

.block-fields input:focus,
.block-fields select:focus,
.block-fields textarea:focus {
  border-color: var(--fg);
  background: #050b14;
  box-shadow: 0 0 0 2px rgba(29, 79, 134, 0.22);
}

.tag-highlight-control {
  position: relative;
  display: grid;
  min-width: 0;
  background: #020202;
  border-radius: var(--soft-radius);
}

.tag-highlight-control:focus-within {
  background: #050b14;
}

.tag-highlight-control .tag-highlight-layer,
.tag-highlight-control input,
.tag-highlight-control textarea {
  grid-area: 1 / 1;
  font-family: Inter, Arial, sans-serif;
  font-size: inherit;
  font-weight: 400;
  font-style: normal;
  font-stretch: normal;
  font-kerning: normal;
  font-variant-ligatures: none;
  letter-spacing: 0;
  tab-size: 2;
}

.tag-highlight-layer {
  z-index: 0;
  width: 100%;
  min-height: 100%;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: var(--soft-radius);
  color: var(--fg);
  line-height: 1.45;
  white-space: pre-wrap;
  overflow: hidden;
  overflow-wrap: normal;
  word-break: normal;
  pointer-events: none;
  text-transform: none;
}

.tag-highlight-control.is-input .tag-highlight-layer {
  min-height: 40px;
  line-height: normal;
  white-space: pre;
}

.tag-highlight-control.is-textarea .tag-highlight-layer,
.tag-highlight-control.is-textarea textarea {
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: normal;
  word-break: normal;
}

.tag-highlight-control.is-input .tag-highlight-layer,
.tag-highlight-control.is-input input {
  line-height: normal;
  white-space: pre;
}

.tag-highlight-control input,
.tag-highlight-control textarea {
  position: relative;
  z-index: 1;
  background: transparent !important;
  color: transparent !important;
  caret-color: var(--fg);
  text-transform: none;
  -webkit-text-fill-color: transparent;
}

.tag-highlight-control input::placeholder,
.tag-highlight-control textarea::placeholder {
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
}

.syntax-html-tag {
  color: #78b7ff;
}

.syntax-md-token {
  color: #ffe07a;
}

.field-rich-preview {
  display: grid;
  gap: 6px;
  border: 1px solid rgba(29, 79, 134, 0.5);
  border-radius: var(--soft-radius);
  background: rgba(7, 26, 53, 0.48);
  padding: 9px 10px;
  color: #e8e8e8;
  line-height: 1.45;
  text-transform: none;
}

.field-rich-preview[hidden] {
  display: none;
}

.field-rich-preview > span {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

.field-rich-preview > div {
  min-height: 22px;
  overflow-wrap: anywhere;
}

.field-rich-preview code {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #050505;
  padding: 1px 5px;
}

.field-rich-preview mark {
  background: var(--fg);
  color: var(--bg);
  padding: 0 3px;
}

.table-editor {
  display: grid;
  gap: 8px;
}

.table-editor-grid {
  display: grid;
  grid-template-columns: repeat(var(--table-columns), minmax(130px, 1fr));
  gap: 1px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--soft-radius);
  background: var(--line);
  scrollbar-width: thin;
}

.table-cell {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 130px;
  min-height: 86px;
  background: #030303;
}

.table-cell.is-header {
  background: #071a35;
}

.table-cell span {
  padding: 6px 8px 0;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

.table-cell textarea {
  min-height: 58px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 8px;
  resize: vertical;
  line-height: 1.35;
}

.table-cell .tag-highlight-control {
  border-radius: 0;
  background: transparent;
}

.table-cell .tag-highlight-control:focus-within {
  background: rgba(29, 79, 134, 0.18);
  box-shadow: inset 0 0 0 1px var(--fg);
}

.table-cell .tag-highlight-layer {
  min-height: 58px;
  border: 0;
  border-radius: 0;
  padding: 8px;
  line-height: 1.35;
}

.table-cell textarea:focus {
  background: rgba(29, 79, 134, 0.18);
  box-shadow: inset 0 0 0 1px var(--fg);
}

.table-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.table-controls button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #020202;
  color: var(--fg);
  padding: 5px 8px;
  font-size: 10px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.table-controls button:hover:not(:disabled) {
  background: var(--navy-soft);
  border-color: var(--navy-line);
  transform: translateY(-1px);
}

.table-controls button:disabled {
  opacity: 0.35;
  cursor: default;
}

.block-empty {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.block-raw {
  border-top: 1px solid var(--line);
  padding: 8px 10px;
  color: var(--muted);
}

.block-raw summary {
  cursor: pointer;
  font-size: 11px;
}

.block-raw pre {
  white-space: pre-wrap;
  color: #d6e5ff;
  text-transform: none;
}

.quick-add {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  overflow-x: auto;
  scrollbar-width: thin;
}

.quick-add span {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.quick-add button,
.empty-editor button {
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #020202;
  color: var(--fg);
  padding: 4px 7px;
  font-size: 10px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.quick-add button:hover,
.empty-editor button:hover {
  background: var(--navy-soft);
  border-color: var(--navy-line);
  transform: translateY(-1px);
}

.empty-editor {
  display: grid;
  place-items: center;
  gap: 12px;
  min-height: 320px;
  border: 1px dashed var(--navy-line);
  border-radius: var(--soft-radius);
  background: linear-gradient(160deg, rgba(7, 26, 53, 0.72), #050505);
  padding: 28px;
  text-align: center;
}

.empty-editor h2 {
  margin: 0;
  font-size: 22px;
}

.empty-editor p {
  max-width: 360px;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.empty-editor div {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.pane-head {
  min-height: 56px;
  height: 56px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.pane-head label {
  color: var(--fg);
  font-size: 13px;
}

.advanced-options {
  position: relative;
  z-index: 8;
}

.advanced-options summary {
  list-style: none;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--toolbar-border);
  border-radius: var(--soft-radius);
  background: #000;
  color: var(--fg);
  padding: 6px 10px;
  font-size: 11px;
  cursor: pointer;
  user-select: none;
}

.advanced-options summary::-webkit-details-marker {
  display: none;
}

.advanced-options[open] summary,
.advanced-options summary:hover {
  background: var(--fg);
  color: var(--bg);
}

.advanced-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  display: grid;
  gap: 8px;
  border: 1px solid var(--navy-line);
  border-radius: var(--soft-radius);
  background: rgba(0, 0, 0, 0.96);
  padding: 10px;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.65);
}

.switch-option {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  color: var(--fg);
  font-size: 11px;
  cursor: pointer;
}

.switch-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-option span {
  position: relative;
  width: 36px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #050505;
  transition: background 140ms ease, border-color 140ms ease;
}

.switch-option span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 140ms ease, background 140ms ease;
}

.switch-option input:checked + span {
  border-color: var(--navy-line);
  background: var(--navy-soft);
}

.switch-option input:checked + span::after {
  transform: translateX(16px);
  background: var(--fg);
}

.switch-option b {
  font-size: 11px;
  font-weight: 500;
}

.editor-wrap {
  position: relative;
  min-height: 0;
  height: 100%;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px) 0 18px / 100% 22px,
    #050505;
  overflow: hidden;
}

.editor-highlights {
  position: absolute;
  inset: 18px 18px auto 18px;
  z-index: 0;
  pointer-events: none;
}

.editor-highlight-line {
  min-height: 22px;
  margin-bottom: 0;
}

.editor-highlight-line.is-heading {
  background: rgba(255, 255, 255, 0.13);
}

.editor-highlight-line.is-quote {
  background: rgba(85, 170, 255, 0.14);
}

.editor-highlight-line.is-code {
  background: rgba(140, 255, 180, 0.12);
}

.editor-highlight-line.is-table {
  background: rgba(255, 214, 102, 0.14);
}

.editor-highlight-line.is-media,
.editor-highlight-line.is-map {
  background: rgba(255, 128, 191, 0.14);
}

.editor-highlight-line.is-details {
  background: rgba(181, 140, 255, 0.14);
}

.editor-highlight-line.is-list {
  background: rgba(102, 255, 232, 0.11);
}

.editor-highlight-line.is-divider,
.editor-highlight-line.is-footer {
  background: rgba(170, 170, 170, 0.1);
}

textarea {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 18px 18px 58px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--fg);
  line-height: 22px;
  font-family: Inter, Arial, sans-serif !important;
  font-size: 15px;
  font-weight: 400 !important;
  font-style: normal;
  font-stretch: normal;
  letter-spacing: 0;
  text-transform: none;
  tab-size: 2;
  overflow: auto;
  caret-color: var(--fg);
  scrollbar-width: thin;
}

.editor-meta {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  max-width: calc(100% - 24px);
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--soft-radius);
  background: rgba(0, 0, 0, 0.86);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  text-transform: uppercase;
  pointer-events: none;
}

.raw-tag-guide {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 2;
  display: flex;
  max-width: calc(100% - 220px);
  gap: 5px;
  flex-wrap: wrap;
  pointer-events: none;
}

.raw-tag-guide span {
  border: 1px solid rgba(200, 221, 255, 0.45);
  border-radius: 5px;
  background: rgba(20, 42, 68, 0.82);
  color: var(--accent);
  padding: 4px 6px;
  font-size: 10px;
  text-transform: none;
}

.preview {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 22px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--fg);
  line-height: 1.5;
  font-family: Inter, Arial, sans-serif;
  font-size: 14px;
  overflow: auto;
  overscroll-behavior: auto;
  scrollbar-width: thin;
}

.preview {
  color: #e8e8e8;
  white-space: normal;
}

.preview::before {
  content: "TELEGRAM PREVIEW";
  display: block;
  width: fit-content;
  margin: 0 auto 14px;
  color: rgba(255, 255, 255, 0.56);
  font-size: 11px;
  text-transform: uppercase;
}

.preview > * {
  max-width: 560px;
  margin-left: auto !important;
  margin-right: auto !important;
}

.preview-block {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
  border-radius: 16px;
  transition: background 140ms ease, box-shadow 140ms ease, outline-color 140ms ease;
}

.preview-block.is-preview-active {
  background: rgba(29, 79, 134, 0.22);
  outline: 2px solid rgba(64, 130, 210, 0.9);
  outline-offset: 4px;
  box-shadow: 0 0 28px rgba(29, 79, 134, 0.45);
}

.preview-block.is-preview-active::before {
  content: "РЕДАКТИРУЕТСЯ";
  position: absolute;
  top: -14px;
  right: 10px;
  z-index: 2;
  border: 1px solid var(--navy-line);
  border-radius: 5px;
  background: var(--navy-soft);
  color: var(--fg);
  padding: 2px 5px;
  font-size: 9px;
  line-height: 1;
}

.preview > p,
.preview > ul,
.preview > table,
.preview > blockquote,
.preview > pre,
.preview > details,
.preview > aside,
.preview > h1,
.preview > h2,
.preview > h3,
.preview > h4,
.preview > .math-preview,
.preview-block > p,
.preview-block > ul,
.preview-block > table,
.preview-block > blockquote,
.preview-block > pre,
.preview-block > details,
.preview-block > aside,
.preview-block > h1,
.preview-block > h2,
.preview-block > h3,
.preview-block > h4,
.preview-block > .math-preview {
  padding: 10px 12px;
  border-radius: 12px;
  background: #1f1f1f;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

.preview h1,
.preview h2,
.preview h3,
.preview h4 {
  margin: 0 0 14px;
  color: var(--fg);
  line-height: 1.15;
}

.preview h1 {
  font-size: 30px;
}

.preview h2 {
  font-size: 24px;
}

.preview h3,
.preview h4 {
  font-size: 19px;
}

.preview p,
.preview ul,
.preview table,
.preview blockquote,
.preview pre,
.preview details,
.preview aside {
  margin: 0 0 14px;
}

.preview ul {
  padding-left: 22px;
}

.preview li {
  margin: 5px 0;
}

.preview a {
  color: var(--fg);
  text-decoration: underline;
}

.preview code {
  border: 1px solid var(--line);
  padding: 1px 5px;
  background: #111;
  border-radius: 5px;
}

.preview pre {
  border: 1px solid var(--line);
  padding: 12px;
  background: #050505;
  white-space: pre-wrap;
  border-radius: var(--soft-radius);
}

.preview pre code {
  border: 0;
  padding: 0;
}

.preview blockquote,
.preview aside {
  border: 1px solid var(--line);
  padding: 12px 14px;
  background: #252525;
  color: #d0d0d0;
  border-radius: 12px;
}

.preview aside {
  background: #0b0b0b;
}

.preview table,
.tooltip table {
  width: 100%;
  border-collapse: collapse;
}

.preview th,
.preview td,
.tooltip th,
.tooltip td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
}

.preview hr {
  border: 0;
  border-top: 1px solid var(--fg);
  margin: 18px 0;
}

.preview mark,
.tooltip mark {
  background: var(--fg);
  color: var(--bg);
  padding: 0 3px;
}

.preview footer {
  color: var(--muted);
  font-size: 12px;
}

.spoiler-demo {
  color: transparent;
  background: var(--fg);
  border-radius: 2px;
  padding: 0 3px;
}

.spoiler-demo:hover {
  color: var(--bg);
}

.emoji-demo {
  border: 1px solid var(--line);
  padding: 0 4px;
}

.media-placeholder {
  border: 1px dashed var(--line);
  color: var(--muted);
  padding: 14px;
  min-height: 48px;
  border-radius: var(--soft-radius);
}

.media-preview {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #050505;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.media-preview img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  background: #111;
}

.media-preview figcaption {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
}

.media-collage,
.media-slideshow {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #050505;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.media-collage {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.media-slideshow {
  display: flex;
  gap: 1px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}

.media-collage figure,
.media-slideshow figure {
  min-width: 0;
  margin: 0;
  background: #050505;
}

.media-slideshow figure {
  flex: 0 0 min(82%, 420px);
  scroll-snap-align: start;
}

.media-collage img,
.media-slideshow img {
  display: block;
  width: 100%;
  height: 220px;
  object-fit: cover;
}

.media-collage figcaption,
.media-slideshow figcaption {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.map-preview {
  margin: 0 0 14px;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #050505;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.map-preview iframe {
  display: block;
  width: 100%;
  height: 260px;
  border: 0;
}

.math-preview {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--soft-radius);
  background: var(--panel-strong);
  color: var(--fg);
  padding: 18px;
  font-size: 22px;
  text-align: center;
  font-family: Inter, Arial, sans-serif;
  font-style: italic;
}

.result {
  min-height: 48px;
  padding: 12px 18px;
  color: var(--muted);
  background: linear-gradient(90deg, #000, var(--navy), #000);
}

.result code {
  color: var(--fg);
  border: 1px solid var(--line);
  padding: 2px 6px;
}

.tooltip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  width: min(260px, calc(100vw - 24px));
  border: 1px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
  padding: 12px;
  border-radius: var(--soft-radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

.format-bar[hidden] {
  display: none;
}

.format-bar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: calc(100vw - 16px);
  padding: 6px;
  border: 1px solid var(--navy-line);
  border-radius: var(--soft-radius);
  background: rgba(3, 10, 20, 0.96);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.72), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  text-transform: uppercase;
}

.format-bar::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 10px;
  height: 10px;
  border-right: 1px solid var(--navy-line);
  border-bottom: 1px solid var(--navy-line);
  background: rgba(3, 10, 20, 0.96);
  transform: translateX(-50%) rotate(45deg);
}

.format-bar button {
  position: relative;
  z-index: 1;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  background: #000;
  color: var(--fg);
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.format-bar button:hover,
.format-bar button:focus-visible {
  border-color: var(--fg);
  background: var(--navy-soft);
  transform: translateY(-1px);
}

.tooltip strong {
  display: block;
  margin-bottom: 8px;
}

.tooltip pre {
  margin: 0;
  white-space: pre-wrap;
}

.modal[hidden],
.tooltip[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  border: 1px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
  padding: 28px;
  border-radius: 8px;
}

.modal-panel h2 {
  margin: 0 0 12px;
  font-size: 28px;
}

.modal-panel p {
  margin: 0 0 18px;
  color: var(--muted);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
  border-radius: var(--soft-radius);
  cursor: pointer;
}

.code-button {
  width: 100%;
  min-height: 64px;
  border: 1px solid var(--fg);
  background: var(--fg);
  color: var(--bg);
  font-family: Inter, Arial, sans-serif;
  font-size: 24px;
  font-weight: 700;
  border-radius: var(--soft-radius);
  cursor: pointer;
}

.copy-status {
  min-height: 20px;
  margin-top: 12px;
  color: var(--fg);
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .actions {
    flex-wrap: wrap;
  }

  .toolbar {
    max-height: none;
    padding: 8px 10px;
    gap: 8px;
    flex-wrap: wrap;
    align-items: flex-start;
    overflow-x: visible;
    overflow-y: visible;
    scroll-snap-type: none;
  }

  .tool-group {
    width: 100%;
    max-width: none;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .tool-group > span {
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 72px;
    background: #050505;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 1fr) minmax(420px, 1fr);
  }

  .pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .block-editor,
  .preview {
    padding: 10px;
  }

  .block-card-head {
    grid-template-columns: auto 1fr auto;
  }

  .block-actions {
    grid-column: 1 / -1;
    overflow-x: auto;
  }

  .block-actions button {
    flex: 1;
  }

  .pane-head {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #050505;
  }

  .advanced-menu {
    right: 0;
    min-width: min(260px, calc(100vw - 24px));
  }

  .preview > * {
    max-width: 100%;
  }

  .raw-tag-guide {
    display: none;
  }
}

@media (max-width: 540px) {
  .format-bar {
    flex-wrap: wrap;
    justify-content: center;
    width: min(360px, calc(100vw - 16px));
  }

  .format-bar button {
    flex: 1 0 auto;
    min-width: 42px;
    padding: 6px 7px;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px 10px;
    padding: 10px;
    align-items: end;
  }

  .brand {
    font-size: 21px;
  }

  .title-input {
    padding: 8px 0;
    font-size: 14px;
  }

  .actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) repeat(3, minmax(52px, 0.6fr));
    gap: 6px;
    overflow: visible;
    width: 100%;
  }

  .history-select {
    max-width: none;
    min-width: 0;
    width: 100%;
  }

  .icon-button {
    min-width: 0;
    width: 100%;
    padding: 6px 7px;
    text-align: center;
  }

  .primary-button {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
  }

  .workspace {
    grid-template-rows: minmax(560px, 1fr) minmax(460px, 1fr);
  }

  .toolbar button,
  .toolbar-upload,
  .icon-button,
  .history-select {
    min-height: 38px;
    white-space: nowrap;
  }

  .tool-group {
    padding: 6px;
  }

  .tool-group > span {
    min-width: 64px;
  }

  .block-kind {
    display: none;
  }

  .block-card-head {
    gap: 7px;
  }

  .block-fields input,
  .block-fields select,
  .block-fields textarea {
    font-size: 16px;
  }
}
