.milkdown {
  --crepe-color-background: #ffffff;
  --crepe-color-on-background: #000000;
  --crepe-color-surface: #f7f7f7;
  --crepe-color-surface-low: #ededed;
  --crepe-color-on-surface: #1c1c1c;
  --crepe-color-on-surface-variant: #4d4d4d;
  --crepe-color-outline: #a8a8a8;
  --crepe-color-primary: #333333;
  --crepe-color-secondary: #cfcfcf;
  --crepe-color-on-secondary: #000000;
  --crepe-color-inverse: #f0f0f0;
  --crepe-color-on-inverse: #1a1a1a;
  --crepe-color-inline-code: #ba1a1a;
  --crepe-color-error: #ba1a1a;
  --crepe-color-hover: #e0e0e0;
  --crepe-color-selected: #d5d5d5;
  --crepe-color-inline-area: #cacaca;

  --crepe-font-title: 'Noto Serif', Cambria, 'Times New Roman', Times, serif;
  --crepe-font-default: 'Noto Sans', Arial, Helvetica, sans-serif;
  --crepe-font-code: 'Space Mono', Fira Code, Menlo, Monaco, 'Courier New', Courier, monospace;

  --crepe-shadow-1: 0px 1px 3px 1px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.3);
  --crepe-shadow-2: 0px 2px 6px 2px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.3);

  position: relative;

  :focus-visible {
    outline: none;
  }

  .milkdown-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .ProseMirror-focused {
    outline: none;
  }

  .ProseMirror {
    padding: 60px 120px;

    *::-moz-selection {
      background: var(--crepe-color-selected);
    }

    *::selection {
      background: var(--crepe-color-selected);
    }

    li.ProseMirror-selectednode {
      background: var(--crepe-color-selected);
      outline: none;

      ::-moz-selection {
        background: transparent;
      }

      ::selection {
        background: transparent;
      }

      &::-moz-selection {
        background: transparent;
      }

      &::selection {
        background: transparent;
      }
    }

    li.ProseMirror-selectednode:after {
      all: unset;
    }

    .ProseMirror-selectednode {
      background: var(--crepe-color-selected);
      outline: none;
      background: color-mix(in srgb, var(--crepe-color-selected), transparent 60%);

      ::-moz-selection {
        background: transparent;
      }

      ::selection {
        background: transparent;
      }

      &::-moz-selection {
        background: transparent;
      }

      &::selection {
        background: transparent;
      }
    }

    &[data-dragging='true'] {
      &::-moz-selection, *::-moz-selection {
        background: transparent;
      }
      .ProseMirror-selectednode,
      &::selection,
      *::selection {
        background: transparent;
      }

      input::-moz-selection {
        background: var(--crepe-color-selected);
      }

      input::selection {
        background: var(--crepe-color-selected);
      }
    }

    img {
      vertical-align: bottom;
      max-width: 100%;

      &.ProseMirror-selectednode {
        background: none;
        outline: 2px solid var(--crepe-color-primary);
      }
    }

    code {
      color: var(--crepe-color-inline-code);
      background: color-mix(in srgb, var(--crepe-color-inline-area), transparent 40%);
      font-family: var(--crepe-font-code);
      padding: 0 2px;
      border-radius: 4px;
      font-size: 87.5%;
      display: inline-block;
      line-height: 1.4286;
    }

    pre {
      background: color-mix(in srgb, var(--crepe-color-inline-area), transparent 40%);
      padding: 10px;
      border-radius: 4px;

      code {
        padding: 0;
        background: transparent;
      }
    }

    blockquote {
      position: relative;
      padding-left: 40px;
      padding-top: 0;
      padding-bottom: 0;
      box-sizing: content-box;
      margin: 4px 0;

      &::before {
        content: '';
        width: 4px;
        left: 0;
        top: 4px;
        bottom: 4px;
        position: absolute;
        background: var(--crepe-color-selected);
        border-radius: 100px;
      }

      hr {
        margin-bottom: 16px;
      }
    }

    hr {
      border: none;
      background-color: color-mix(in srgb, var(--crepe-color-outline), transparent 80%);
      background-clip: content-box;
      padding: 6px 0;
      height: 13px;
      position: relative;

      &.ProseMirror-selectednode {
        outline: none;
        background-color: color-mix(in srgb, var(--crepe-color-outline), transparent 20%);
        background-clip: content-box;

        &::before {
          content: '';
          position: absolute;
          left: 0;
          top: 0;
          bottom: 0;
          right: 0;
          background-color: color-mix(in srgb, var(--crepe-color-outline), transparent 80%);
          pointer-events: none;
        }
      }
    }

    ul,
    ol {
      padding: 0;
    }

    /* Link styling for clickable links */
    a[href] {
      color: #2563eb;
      text-decoration: underline;
      cursor: pointer;
      transition: color 0.2s ease;
    }

    a[href]:hover {
      color: #1d4ed8;
      text-decoration: underline;
    }

    .dark a[href] {
      color: #60a5fa;
    }

    .dark a[href]:hover {
      color: #93c5fd;
    }
  }

  .milkdown-code-block {
    display: block;
    position: relative;
    /* background: var(--crepe-color-surface); */
    margin: 20px 0;

    .language-picker {
      padding-top: 10px;
      width: -moz-max-content;
      width: max-content;
      position: absolute;
      z-index: 1;
      color: var(--crepe-color-on-surface);
    }

    .hidden {
      display: none !important;
    }

    &.selected {
      outline: 1px solid var(--crepe-color-primary);
    }

    .cm-editor {
      outline: none !important;
      background: transparent;
    }

    .cm-gutters {
      border-right: none;
      padding-right: 2px;
    }

    .cm-line {
      padding: 4px 10px;
    }

    .tools {
      display: flex;
      justify-content: space-between;
      align-items: center;

      input {
        caret-color: var(--crepe-color-outline);
      }

      .preview-toggle-button {
        background: var(--crepe-color-secondary);
        color: var(--crepe-color-on-surface-variant);
        padding: 4px 10px;
        opacity: 0;
        cursor: pointer;
        border-radius: 100px;
        font-size: 12px;
        line-height: 16px;
        font-weight: 600;
        font-family: var(--crepe-font-default);
        transition: opacity 0.2s ease-in-out;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;

        svg {
          width: 14px;
          height: 14px;
          fill: var(--crepe-color-on-surface-variant);
        }
      }

      .language-button {
        display: flex;
        align-items: center;
        font-family: var(--crepe-font-default);
        gap: 6px;
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 12px;
        font-weight: 600;
        line-height: 16px;
        opacity: 1;
        cursor: pointer;
        transition: opacity 0.2s ease-in-out;

        .expand-icon {
          transition: transform 0.2s ease-in-out;
          width: 18px;
          height: 18px;
          display: flex;
          justify-content: center;
          align-items: center;
        }

        .expand-icon svg {
          width: 14px;
          height: 14px;
          color: white;
        }

        &[data-expanded='true'] .expand-icon {
          transform: rotate(180deg);
        }

        .expand-icon svg:focus,
        .expand-icon:focus-visible {
          outline: none;
        }
      }
    }

    &:hover .preview-toggle-button {
      opacity: 1;
    }

    .list-wrapper {
      background: var(--crepe-color-surface-low);
      border-radius: 12px;
      box-shadow: var(--crepe-shadow-1);
      width: 240px;
      padding-top: 12px;
    }

    .language-list {
      height: 410px;
      overflow-y: auto;
      overscroll-behavior: contain;
      margin: 0;
      padding: 0;
    }

    .language-list-item {
      cursor: pointer;
      margin: 0;
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 4px 22px;
      font-size: 14px;
      font-weight: 600;
      line-height: 20px;

      &:hover {
        background: var(--crepe-color-hover);
      }

      &:focus-visible {
        outline: none;
        background: var(--crepe-color-hover);
      }

      .leading,
      .leading svg {
        width: 24px;
        height: 24px;
      }

      &.no-result {
        cursor: default;
        opacity: 0.6;

        &:hover {
          background: transparent;
        }
      }
    }

    .search-box {
      display: flex;
      align-items: center;
      margin: 0 12px 8px;
      background: transparent;
      border-radius: 4px;
      outline: 1px solid var(--crepe-color-primary);
      gap: 8px;
      padding: 6px 10px;

      &:has(input:focus) {
        outline: 2px solid var(--crepe-color-primary);
      }

      .search-input {
        width: 100%;
        color: var(--crepe-color-on-surface);
      }

      .search-icon {
        display: none;
      }

      .clear-icon {
        cursor: pointer;
        width: 20px;
        height: 20px;

        svg {
          width: 20px;
          height: 20px;
          color: var(--crepe-color-primary);
          fill: var(--crepe-color-primary);
        }

        &:hover {
          background: var(--crepe-color-hover);
        }
      }

      input {
        font-family: var(--crepe-font-default);
        font-size: 14px;
        line-height: 20px;
        background: transparent;
      }

      input:focus {
        outline: none;
      }
    }
  }
}

