.block-content-wrapper {
  user-select: text;
  @screen sm {
    overflow-x: visible;
  }
}

.block-content {
  @apply min-h-[24px] max-w-full whitespace-pre-wrap break-words cursor-text;

  img {
    max-width: 100%;

    /* FIXME: img macros */

    &.left {
      float: left;
    }

    &.right {
      float: right;
    }

    &.loading-asset {
      width: 9px;
    }
  }

  .asset-container {
    @apply relative inline-block mt-2;

    .asset-action-bar {
      @apply top-0.5 right-0.5 absolute flex items-center
      border bg-gray-02 rounded opacity-0 transition-opacity;
    }

    .asset-action-btn {
      @apply m-1 p-0.5 truncate flex items-center opacity-70 select-none
      hover:opacity-90 active:opacity-60;
    }

    &:hover, &:active {
      .asset-action-bar {
        @apply opacity-100;
      }
    }
  }

  .resize {
    display: inline-flex;
    /* Fix chrome missing resize handle issue https://bugs.chromium.org/p/chromium/issues/detail?id=1135676&q=css%20resize%20type%3DBug&can=2.*/
    transform: translate3d(0, 0, 0);
  }

  .draw [aria-labelledby="shapes-title"] {
    position: absolute;
    left: 50%;
    transform: translate(-50%);
  }

  &-fallback-ui {
    padding: 10px 15px;
    border-color: var(--ls-secondary-border-color);
  }

  [data-tooltipped]:has(a.tag) {
    @apply px-0.5;
  }
}

.block-content-or-editor-wrap {
  @apply flex flex-1 flex-row flex-wrap gap-1;
}

.block-head-wrap {
  @apply flex flex-1 w-full flex-row flex-wrap;
  @apply justify-between items-center;
}

.breadcrumb {
  .asset-container > img {
    height: 18px;
    width: unset !important;
  }

  .inline-wrap {
    & > div, & > div > div {
      display: inherit;
    }
  }

  &.block-parents {
    .ui__icon {
      position: relative;
      top: 4px;
    }

    a {
      color: var(--ls-primary-text-color);

      &:hover {
        opacity: 1;
      }
    }
  }

  .page-ref {
    @apply inline-flex items-baseline;
  }
}

.open-block-ref-link {
  background-color: var(--ls-page-properties-background-color);
  padding: 1px 4px;
  border-radius: 2px;
}

.block-body {
  blockquote:first-child,
  pre:first-child {
    margin-top: 8px;
    margin-bottom: 8px;
  }
}

.block-body ul,
.block-body ol,
.block-body dl {
  margin-bottom: 0;

  > li {
    margin: 0;
  }
}

.block-body ol {
  list-style-position: inside;
  margin-left: 0;

  > li {
    &::marker,
    > p {
      display: initial;
    }
  }
}

.block-children-container {
  position: relative;
  margin-left: 29px;
}

.block-children-left-border {
  z-index: 1;
  width: 4px;
  left: -1px;
  top: 0;
  height: 100%;
  cursor: pointer;
  background-clip: content-box;
  background-color: transparent;
  position: absolute;
  border-radius: 2px;
  opacity: 0.6;
  border-left-color: var(--lx-gray-09, var(--ls-border-color, var(--rx-gray-09)));

  &:hover {
    background-color: var(--lx-gray-10, var(--ls-primary-text-color, var(--rx-gray-10)));
    opacity: .7;
  }

  &:active {
    opacity: 1;
  }
}

.block-children {
  border-left: 1px solid;
  border-left-color: var(--lx-gray-04-alpha, var(--ls-guideline-color, var(--rx-gray-04-alpha))) !important;
}

.hidden-block .block-children {
  border-left: 0;
}

.block-control-wrap, .ls-page-title .property-value .block-control-wrap {
  @apply h-[24px];

  &.is-order-list {
    @apply mr-0 pr-0;

    .bullet-link-wrap {
      @apply relative left-[-3px];
    }
  }

  &.bullet-hidden {
    padding-right: 2px;
  }
}

.ls-page-title .block-control-wrap {
  height: initial;
}

.block-title-wrap {
  @apply inline;

  > .ui__checkbox {
    @apply relative top-[2px];

    > span {
      @apply h-full;
    }
  }

  &.as-heading {
    @apply flex flex-1 items-center;

    > .ui__checkbox {
      @apply top-0;
    }

    h1& {
      .ui__icon.ti svg {
        @apply w-8 h-7;
      }
    }

    h2& {
      .ui__icon.ti svg {
        @apply w-7 h-6;
      }
    }

    h3& {
      .ui__icon.ti svg {
        @apply w-5 h-5;
      }
    }
  }

  &:has(.dsl-query), &:has(.embed-page) {
    @apply flex flex-row w-full;

    > .embed-page {
      @apply w-full;
    }
  }

  .dsl-query {
    @apply w-full;
  }
}

.block-control {
  @apply decoration-0 text-sm cursor-default
  min-w-[22px] min-h-[22px] p-0.5 select-none opacity-40;

  .control-hide {
    @apply hidden;
  }

  &:active {
    @apply opacity-30;
  }
}

.block-left-menu {
  background-color: var(--ls-secondary-background-color);
  background: linear-gradient(90deg, var(--ls-primary-background-color) 0%, var(--ls-secondary-background-color) 100%);

  .commands-button {
    @apply overflow-hidden flex max-w-[40px];

    .indent {
      @apply flex items-center w-full justify-center opacity-30;
    }
  }
}

.block-right-menu {
  background-color: var(--ls-secondary-background-color);
  /* background: linear-gradient(-90deg, var(--ls-primary-background-color) 0%, var(--ls-secondary-background-color) 100%); */

  .commands-button {
    @apply overflow-hidden flex flex-nowrap;

    .outdent, .more {
      @apply flex items-center justify-center
      overflow-hidden opacity-30 m-0 w-[40px];
    }
  }
}

.block-ref {
  @apply border-b-[0.5px] border-b-[--ls-block-ref-link-text-color] cursor-alias;

  display: inherit;
  margin-bottom: -1px;

  .block-ref {
    @apply mx-1;
  }

  &:hover {
    color: var(--ls-link-text-hover-color);
  }

  .block-content {
    cursor: inherit;

    &-inner {
      display: inherit;

      > * {
        display: inherit;
      }
    }
  }
}

.block-ref-no-title {
  border-bottom: 0.5px solid;
  border-bottom-color: var(--ls-block-ref-link-text-color);
  cursor: alias;
  padding: 2px 5px;
  display: block;

  &:hover {
    color: var(--ls-link-text-hover-color);
  }

  .block-content {
    cursor: inherit;
  }
}

.page-reference {
  @apply rounded transition-[background];

  .bracket {
    @apply opacity-30;
  }

  &:hover {
    background: var(--lx-accent-04-alpha, var(--ls-secondary-background-color, hsl(var(--primary)/.4)));
  }
}

.page-ref {
  @apply inline;
  color: var(--lx-accent-11, var(--ls-link-text-color, hsl(var(--primary)/.8)));

  &:hover {
    color: var(--lx-accent-11, var(--ls-link-text-color, hsl(var(--primary))));
  }

  .ui__icon.ti {
    @apply relative top-[3px] left-0;
  }
}

.asset-ref {
  &-wrap {
    &[data-ext=pdf] {
      display: inline-flex;
      align-items: center;
    }
  }

  &.is-doc {
    &:before {
      content: "[[📜";
      opacity: .7;
      margin-right: 4px;
    }

    &:after {
      content: "]]";
      opacity: .7;
    }
  }
}

.embed-page {
  @apply py-2 my-2 px-2;

  > section {
    margin-bottom: 5px;
  }

  &.in-sidebar {
    background-color: var(--ls-tertiary-background-color);
  }
}

.block-properties, .page-properties {
  margin: 4px 0;
  padding: 4px 8px;
  background-color: var(--lx-gray-03, var(--ls-block-properties-background-color, var(--rx-gray-03)));
}

.block-marker {
  padding: 2px 4px;
  opacity: 0.7;
  font-size: 85%;
  margin: 0 2px 0 0;
  font-weight: 650;
  border: 0;
}

.marker-switch {
  &:hover {
    color: var(--ls-link-text-hover-color);
    opacity: 1;
  }
}

.block-main-container {
  @apply min-h-[24px];

  &[data-has-heading="1"], &:has(textarea.h1) {
    > .block-control-wrap {
      @apply relative top-4;
    }

    .block-content-or-editor-wrap {
      .positioned-properties {
        @apply relative top-4;
      }
    }
  }

  &[data-has-heading="2"], &:has(textarea.h2) {
    > .block-control-wrap {
      @apply relative top-3;
    }

    .block-content-or-editor-wrap {
      .positioned-properties {
        @apply relative top-3;
      }
    }
  }

  &[data-has-heading="3"], &:has(textarea.h3) {
    > .block-control-wrap {
      @apply relative top-[2px];
    }

    .block-content-or-editor-wrap {
      .positioned-properties {
        @apply relative top-[3px];
      }
    }
  }

  &[data-has-heading="5"] {
    > .block-control-wrap {
      @apply relative -top-[1px];
    }
  }

  &[data-has-heading="6"], &:has(textarea.h6) {
    h6.as-heading, textarea.h6 {
      @apply pt-1;
    }
  }
}

.ls-block {
  @apply relative py-0.5 transition-[background-color] mx-auto;

  &.selected {
    @apply rounded;
  }
}

.ls-block h1,
.editor-inner .h1.uniline-block {
  font-size: 2em;
  min-height: 1.5em;
}

.ls-block h2,
.editor-inner .h2.uniline-block {
  font-size: 1.5em;
  min-height: 1.5em;
}

.ls-block h3,
.editor-inner .h3.uniline-block {
  font-size: 1.2em;
  min-height: 1.2em;
}

.ls-block h4,
.editor-inner .h4.uniline-block {
  font-size: 1em;
  min-height: 1em;
}

.ls-block h5,
.editor-inner .h5.uniline-block {
  font-size: 0.83em;
  min-height: 0.83em;
}

.ls-block h6,
.editor-inner .h6.uniline-block {
  font-size: 0.75em;
  min-height: 0.75em;
}

.ls-block :is(h1, h2, h3, h4, h5, h6),
.editor-inner .uniline-block:is(.h1, .h2, .h3, .h4, .h5, .h6),
.editor-inner .multiline-block:is(.h1, .h2, .h3, .h4, .h5, .h6)::first-line {
  font-weight: 600;
}

.ls-block :is(h1, h2),
.editor-inner .uniline-block:is(.h1, .h2) {
  @apply border-b border-gray-06 mt-1 mb-2 pb-1;
}

.block-ref .ls-block :is(h1, h2),
.block-ref .editor-inner :is(.h1, .h2) {
  border-bottom: none;
}

.block-ref :is(h1, h2, h3, h4, h5, h6) {
  border-bottom: none;
  font-size: 1rem;
}

.document-mode {
  & .ls-block h1,
  & .editor-inner .h1 {
    margin: 0.67em 0;
  }

  & .ls-block h2,
  & .editor-inner .h2 {
    margin: 0.75em 0;
  }

  & .ls-block h3,
  & .editor-inner .h3 {
    margin: 0.83em 0;
  }

  & .ls-block h4,
  & .editor-inner .h4 {
    margin: 1.12em 0;
  }

  & .ls-block h5,
  & .editor-inner .h5 {
    margin: 1.5em 0;
  }

  & .ls-block h6,
  & .editor-inner .h6 {
    margin: 1.67em 0;
  }
}

.color-level {
  background-color: var(--lx-gray-02, var(--color-level-1, var(--rx-gray-02)));

  .dark & {
    background-color: var(--lx-gray-01, var(--color-level-1, var(--rx-gray-01)));
  }

  & .color-level {
    background-color: var(--color-level-2);

    & .color-level {
      background-color: var(--color-level-3);

      & .color-level {
        background-color: var(--color-level-4);

        & .color-level {
          background-color: var(--color-level-5);

          & .color-level {
            background-color: var(--color-level-6);

            & .color-level {
              background-color: var(--color-level-4);

              & .color-level {
                background-color: var(--color-level-5);

                & .color-level {
                  background-color: var(--color-level-6);

                  & .color-level {
                    background-color: var(--color-level-4);

                    & .color-level {
                      background-color: var(--color-level-6);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

.color-level-1 {
  background-color: var(--color-level-1);
}

.color-level-2 {
  background-color: var(--color-level-2);
}

.color-level-3 {
  background-color: var(--color-level-3);
}

.color-level-4 {
  background-color: var(--color-level-4);
}

.color-level-5 {
  background-color: var(--color-level-5);
}

.color-level-6 {
  background-color: var(--color-level-6);
}

.bullet-container {
  display: flex;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  justify-content: center;
  align-items: center;

  .bullet-heading {
    background-color: var(--ls-block-bullet-color, #8fbc8f);
  }

  &.as-order-list {
    @apply w-[22px] whitespace-nowrap justify-center pl-[3px];
  }

  .bullet {
    @apply rounded-full w-[6px] h-[6px] text-[15px] opacity-80;

    > * {
      @apply cursor-pointer;
    }
  }

  &:not(.typed-list) {
    &.bullet-closed {
      background-color: var(--lx-gray-04-alpha, var(--ls-block-bullet-border-color, var(--rx-gray-04-alpha)));
    }

    .bullet {
      background-color: var(--lx-gray-08, var(--ls-block-bullet-color, var(--rx-gray-08)));
      transition: transform 0.2s;
    }
  }

  &.typed-list:not(:focus-within) {
    .bullet {
      background-color: unset;
      height: unset;
      width: unset;
      box-shadow: none;
    }
  }
}

.bullet-link-wrap {
  color: var(--ls-primary-text-color);

  .ui__icon {
      @apply opacity-80;
  }

  &:hover > .bullet-container:not(.typed-list) {
    background-color: var(--lx-gray-04-alpha, var(--ls-block-bullet-border-color, var(--rx-gray-04-alpha)));

    .bullet {
      transform: scale(1.2);
      background-color: var(--lx-gray-08, var(--ls-block-bullet-color, var(--rx-gray-08))) !important;
    }
  }
}

.content.doc-mode {
  margin-left: -16px;

  .block-children-left-border {
    display: none;
  }

  .block-children {
    border-left: none;
  }

  .hide-inner-bullet .bullet {
    display: none;
  }

  .block-children-container {
    margin-left: 18px;
  }
}

.ls-block .custom-query {
  > .th {
    @apply flex flex-row flex-1 items-center justify-between my-1 text-xs opacity-90;
  }
}

/* copied from https://github.com/drdogbot7/tailwindcss-responsive-embed */
.embed-responsive {
  position: relative;
  display: block;
  height: 0;
  padding: 0;
  overflow: hidden;

  .embed-responsive-item,
  iframe,
  embed,
  object,
  video {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100%;
    width: 100%;
    border: 0;
  }
}

.embed {
  border-radius: var(--ls-border-radius-low);
}

.embed-header {
  font-weight: 600;
}

a.filter svg {
  transform: scale(0.9);
}

.table-query-properties svg {
  display: inline;
}

.query-title {
  background: var(--ls-page-properties-background-color);
}

.ls-card {
  height: 100%;
}

.ls-card a[data-ref="card"], .ls-card .page-reference[data-ref="card"] {
  display: none;
}

a.cloze {
  color: var(--ls-cloze-text-color);
}

a.cloze-revealed {
  color: var(--ls-cloze-text-color);
  text-decoration: underline;
  text-underline-position: under;
}

.page-property-key {
  @apply font-medium whitespace-nowrap;
  color: var(--ls-secondary-text-color);
}

.page-property-key:hover {
  background-color: var(--ls-selection-background-color);
}

.cp__fenced-code-block {
  .not-edit {
    cursor: default;
  }
}

html.is-native-ios {
  audio {
    width: 100%;
    max-width: 350px;
  }
}

html:not(.is-mac) {
  body[data-active-keystroke="Control"] {
    .block-content {
      cursor: pointer;
    }
  }
}

html.is-mac {
  body[data-active-keystroke="Meta"] {
    .block-content {
      cursor: pointer;
    }
  }
}

.references-blocks {
  @apply mb-3;

  &-wrap {
    .foldable-title {
      @apply ml-3;

      .block-control {
        @apply relative right-[-5px] top-[1px];
      }
    }
  }

  &-item {
    @apply bg-gray-03 rounded p-4;

    > .only-page-blocks {
      @apply relative -left-[11px];
    }

    .with-foldable-page {
      > .preview-ref-link {
        .page-ref .ui__icon.ti {
          @apply top-[2px] left-0;
        }
      }
    }
  }

  .page-reference:hover {
    background: var(--lx-accent-04-alpha, var(--ls-tertiary-background-color, hsl(var(--primary)/.4)));
  }
}

.cp__right-sidebar-inner {
  .references-blocks-item {
    @apply bg-gray-04;
  }
}

.block-title-wrap a.tag, .block-body a.tag {
  font-size: initial;
  opacity: 1;
}

.positioned-properties.right-align  {
  button {
    white-space: nowrap;
  }
  .block-title-wrap {
    @apply overflow-hidden h-6;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}

.block-tags {
    @apply flex flex-row flex-wrap self-start items-center;
    min-height: 24px;
    max-width: 256px;
    margin-right: -28px;
}
.block-tag {
    @apply pr-1 flex flex-row items-center gap-1;
}

.block-tag a.tag {
    @apply flex text-sm items-center opacity-70;
}

.block-tag a.tag:hover {
    @apply opacity-100;
}
.block-tag span {
    @apply whitespace-nowrap overflow-hidden;
    max-width: 160px;
    text-overflow: ellipsis;
}

.ls-table a.tag {
    @apply text-sm;
}

.block-content-wrapper svg, .view-actions svg {
    width: 18px;
    height: 18px;
}

.ls-page-title .ls-page-icon svg, .ls-page-title .ls-page-icon button {
    width: 38px;
    height: 38px;
}

.ls-page-title .positioned-properties svg {
    width: 24px;
    height: 24px;
}

.ls-page-title .ls-page-icon button {
    margin-top: 8px;
}

.ls-page-title .positioned-properties {
    height: 54px;
    overflow: hidden;
}
