.shikitor {
  --gutter-width: 3em;
  --line-height: 22px;
  --cursor-width: 2px;

  position: relative;
  display: flex;

  line-height: var(--line-height);
  transition: .1s;

  overflow: hidden;
  &-bg-lighting {
    position: relative;
    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: var(--shikitor-fg-color, white);
      opacity: .5;
      pointer-events: none;
    }
  }
  &-input, &-output {
    position: absolute;
    width: 100%;
    height: 100%;
    inset: 0;
    margin: 0;
    padding: 0;
    border: 0;
    font-family: var(--font-family, monospace), serif;
    font-size: inherit;
    &::selection {
      color: transparent;
      background-color: var(--shikitor-fg-color-op6, black);
    }
  }
  &.line-numbers &-gutter-line-number {
    margin: 0 10px;
    width: var(--shikitor-line-digit-count, 0px);
  }
  &-gutter-line {
    display: flex;
    &-number {
      width: 0;

      user-select: none;
      text-align: right;
      font-family: var(--font-family, monospace), serif;
      overflow: hidden;
    }
    &-highlighted::before {
      z-index: 10;
      position: absolute;
      content: '';
      left: 0;
      width: 100%;
      height: var(--line-height);
      background-color: var(--shikitor-fg-color);
      opacity: .3;
      pointer-events: none;
    }
  }
  &-container {
    position: relative;
    flex-grow: 1;
    width: 0;
  }
  &-input {
    resize: none;
    color: transparent;
    caret-color: transparent;
    background-color: transparent;
    outline: none;
    overflow: auto;
    white-space: pre;
    line-height: var(--line-height);
  }
  &-output {
    height: 100%;
    overflow: hidden;
    user-select: none;
    > pre {
      margin: 0;
    }
    &-lines {
      display: block;
      line-height: var(--line-height);
    }
    &-line {
      position: relative;
      min-width: calc(100% - var(--gutter-width));
    }
    .tab, .space {
      position: relative;
    }
    .tab::before {
      content: '⇥';
      position: absolute;
      opacity: .3;
    }
    .space::before {
      content: '·';
      position: absolute;
      opacity: .3;
    }
  }
  &-placeholder {
    position: absolute;
    top: 0;
    color: color-mix(in srgb, var(--fg), var(--bg) 50%);
  }
  &-cursors {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
    user-select: none;
  }
  &-cursor {
    position: absolute;
    width: var(--cursor-width);
    height: calc(var(--line-height) - 2px);
    margin-top: calc(
      var(--shikitor-cursor-t, 0px) + -1 * var(--shikitor-scroll-t, 0px) + 1px
    );
    margin-left: calc(
      var(--shikitor-cursor-l, 0px) + -1 * var(--shikitor-scroll-l, 0px)
    );
    z-index: 10;
    pointer-events: none;
    &--ch {
      --cursor-width: 1ch;
    }
    &#{&}--visible::after {
      visibility: visible;
    }
    &::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      visibility: hidden;
      background-color: var(--shikitor-caret-color, white);
      pointer-events: none;
    }
    &__username {
      --h: 14px;

      pointer-events: none;
      z-index: 10;

      position: sticky;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      margin-top: calc(
        var(--shikitor-cursor-t, 0px) + -1 * var(--shikitor-scroll-t, 0px) -
          14px
      );
      margin-left: calc(
        var(--shikitor-cursor-l, 0px) + -1 * var(--shikitor-scroll-l, 0px)
      );

      width: 0;
      height: 0;
      &::before {
        content: '';
        position: absolute;
        top: var(--h);
        left: var(--cursor-width);
        width: 0;
        height: 0;
        border: 5px solid transparent;
        border-top-color: var(--shikitor-caret-color, white);
        transform: translateX(-50%) rotate(-90deg);
        transform-origin: 50% 0;
      }
      &::after {
        display: inline-block;
        content: attr(data-username);

        position: absolute;
        top: 0;
        left: var(--cursor-width);
        padding: 1px 2px;
        border-radius: 3px 3px 3px 0;
        background-color: var(--shikitor-caret-color, white);

        font-size: 12px;
        line-height: 12px;
        font-weight: bold;
        color: var(--shikitor-bg-color, white);
      }
    }
  }
  &.hide-self-cursor-username {
    .shikitor-cursor__username {
      display: none;
    }
  }
}
