:root {
  --tiptap-border-radius: 0.5em;
}

/* Book writing (pages) */
:where(tiptap-editor.page__editor) {
  font-size: 0.8em;

  .tiptap-content,
  .ProseMirror {
    font-family: var(--font-book);
    text-align: justify;
    text-justify: inter-word;
  }

  .ProseMirror {
    --paragraph-indent: 1.4em;

    p {
      text-indent: var(--paragraph-indent);
    }

    :where(blockquote, pre, ul, ol, hr, figure, table) + p {
      text-indent: 0;
    }

    :where(blockquote, li) p {
      text-indent: 0;
    }
  }
}

/* Editor Container */
:where(tiptap-editor) {
  display: flex;
  flex-direction: column;
  flex-grow: 1;

  &:invalid {
    border: var(--color-negative) 2px solid;
  }
}

/* Toolbar */
:where(tiptap-toolbar) {
  --hover-size: 0;

  border-radius: var(--tiptap-border-radius);
  display: inline-flex;
  gap: 0.1em;

  :is(button, label) {
    aspect-ratio: 6/5;
    align-items: center;
    appearance: none;
    background-color: transparent;
    border: none;
    border-radius: var(--tiptap-border-radius);
    cursor: pointer;
    display: inline-flex;
    flex-shrink: 0;
    inline-size: auto;
    justify-content: center;
    min-block-size: 2em;
    transition: background-color 300ms ease;

    :is(img, svg) {
      -webkit-touch-callout: none;
      block-size: 1em;
      fill: currentColor;
      inline-size: auto;
      user-select: none;
    }

    &:where(:focus-visible) {
      background-color: var(--color-bg);
    }

    @media (hover: hover) {
      &:hover {
        background-color: var(--color-bg);
      }
    }

    &:where(:active),
    &:where(.active) {
      background-color: var(--color-selected-dark);
    }
  }
}

/* Tiptap Content Area */
:where(.tiptap-content) {
  caret-color: var(--color-link);
  flex-grow: 1;
  min-block-size: 50dvh;
  text-align: start;

  &:focus,
  &:active {
    border: none;
    outline: none;
  }
}

/* ProseMirror Editor (Tiptap internal) */
:where(.ProseMirror) {
  outline: none;
  min-block-size: 100%;

  &:focus {
    outline: none;
  }

  /* Placeholder */
  p.is-editor-empty:first-child::before {
    color: var(--color-subtle);
    content: attr(data-placeholder);
    float: left;
    height: 0;
    pointer-events: none;
  }

  /* Typography */
  h1, h2, h3, h4, h5, h6 {
    font-weight: bold;
    line-height: 1.2;
    margin-block: 1em 0.5em;
  }

  h1 { font-size: 2em; }
  h2 { font-size: 1.5em; }
  h3 { font-size: 1.25em; }
  h4 { font-size: 1.1em; }
  h5 { font-size: 1em; }
  h6 { font-size: 0.9em; }

  p {
    margin-block: 0.5em;
  }

  /* Lists */
  ul, ol {
    padding-inline-start: 1.5em;
    margin-block: 0.5em;
  }

  ul {
    list-style-type: disc;
  }

  ol {
    list-style-type: decimal;
  }

  li {
    margin-block: 0.25em;
  }

  /* Blockquote */
  blockquote {
    border-inline-start: 3px solid var(--color-subtle);
    margin-inline: 0;
    padding-inline-start: 1em;
    color: var(--color-ink-subtle);
    font-style: italic;
  }

  /* Code */
  code {
    background-color: var(--color-subtle);
    border-radius: 0.25em;
    font-family: monospace;
    padding: 0.1em 0.3em;
  }

  pre {
    background-color: var(--color-subtle);
    border-radius: var(--tiptap-border-radius);
    font-family: monospace;
    margin-block: 0.5em;
    overflow-x: auto;
    padding: 1em;

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

  /* Links */
  a {
    color: var(--color-link);
    text-decoration: underline;
    cursor: pointer;
  }

  /* Images */
  img {
    max-inline-size: 100%;
    block-size: auto;
    border-radius: var(--tiptap-border-radius);
    margin-block: 0.5em;
  }

  /* Horizontal Rule */
  hr {
    border: none;
    border-block-start: 1px solid var(--color-subtle);
    margin-block: 1em;
  }

  /* Strong and Emphasis */
  strong {
    font-weight: bold;
  }

  em {
    font-style: italic;
  }

  s {
    text-decoration: line-through;
  }
}

.synonyms-menu {
  background-color: var(--color-bg);
  border: 1px solid var(--color-subtle);
  border-radius: 0.8em;
  color: var(--color-ink);
  inline-size: min(32ch, calc(100vw - 2rem));
  padding: 0.75em;
  position: fixed;
  z-index: 10;
}

.synonyms-menu__header {
  margin-block-end: 0.5em;
}

.synonyms-menu__list {
  display: grid;
  gap: 0.25em;
}

.synonyms-menu__item {
  --btn-border-radius: 0.6em;
  --btn-padding: 0.45em 0.6em;
  --btn-border-size: 0;
  --hover-size: 0;

  justify-content: start;
  inline-size: 100%;
  text-align: start;
}
