/* Lexxy Editor Styles - Adapted from Fizzy for Tailwind dark mode
/* ============================================================================ */

/* CSS Variables for Lexxy
/* ---------------------------------------------------------------------------- */

:root {
  /* Spacing */
  --block-space: 1rem;
  --block-space-half: 0.5rem;

  /* Typography */
  --font-sans: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-base: var(--font-sans);
  --text-small: 0.875rem;
  --text-x-small: 0.75rem;

  /* Focus rings */
  --focus-ring-color: #3b82f6;
  --focus-ring-offset: 1px;
  --focus-ring-size: 2px;

  /* Colors - Light mode */
  --color-canvas: #ffffff;
  --color-ink: #1f2937;
  --color-ink-dark: #4b5563;
  --color-ink-medium: #6b7280;
  --color-ink-light: #d1d5db;
  --color-ink-lighter: #e5e7eb;
  --color-ink-lightest: #f3f4f6;
  --color-ink-inverted: #ffffff;
  --color-link: #2563eb;
  --color-selected: #dbeafe;
  --color-selected-dark: #93c5fd;
  --color-selected-light: #eff6ff;

  /* OKLCH colors for selections */
  --lch-blue-light: 84% 0.07 255;

  /* Shadows */
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

/* Dark mode variables */
.dark {
  --color-canvas: #000000;
  --color-ink: #e5e7eb;
  --color-ink-dark: #9ca3af;
  --color-ink-medium: #6b7280;
  --color-ink-light: #374151;
  --color-ink-lighter: #1f2937;
  --color-ink-lightest: #111827;
  --color-ink-inverted: #000000;
  --color-link: #60a5fa;
  --color-selected: #1e3a5f;
  --color-selected-dark: #3b82f6;
  --color-selected-light: #172554;
  --focus-ring-color: #60a5fa;

  --lch-blue-light: 40% 0.094 260;

  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.3);
}

/* Editor
/* ---------------------------------------------------------------------------- */

lexxy-editor {
  display: block;
  position: relative;
  overflow: visible;
}

lexxy-editor figure.node--selected {
  &:has(img) {
    img {
      outline: var(--focus-ring-size) solid var(--focus-ring-color);
      outline-offset: var(--focus-ring-offset);
    }
  }

  &:not(:has(img)) {
    outline: var(--focus-ring-size) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
  }
}

/* Lexical uses the `lexxy-editor--empty` class even if you have a list
 * started but haven't added other characters. Here, we hide the placeholder
 * when you click the List button in the toolbar. */
.lexxy-editor--empty {
  .lexxy-editor__content:not(:has(ul, ol))::before {
    content: attr(placeholder);
    color: currentColor;
    cursor: text;
    opacity: 0.5;
    pointer-events: none;
    position: absolute;
    white-space: pre-line;
  }
}

.lexxy-editor__content {
  margin-block-start: var(--block-space-half);
  min-block-size: calc(7lh + var(--block-space));
  outline: 0;
  color: var(--color-ink);
}

/* Allow color highlights to show through a bit */
.lexxy-editor__content ::selection {
  background: oklch(var(--lch-blue-light) / 0.5);
}

.lexxy-editor__content > :last-child {
  margin-block-end: 0;
}

.lexxy-editor--drag-over {
  background-color: var(--color-selected);
  border-radius: 4px;
  outline: 2px dashed var(--color-selected-dark);
}

/* Code language picker */
.lexxy-code-language-picker {
  --caret-icon: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m12 19.5c-.7 0-1.3-.3-1.7-.8l-9.8-11.1c-.7-.8-.6-1.9.2-2.6.8-.6 1.9-.6 2.5.2l8.6 9.8c0 .1.2.1.4 0l8.6-9.8c.7-.8 1.8-.9 2.6-.2s.9 1.8.2 2.6l-9.8 11.1c-.4.5-1.1.8-1.7.8z' fill='%231f2937'/%3E%3C/svg%3E");

  -webkit-appearance: none;
  appearance: none;
  background-color: var(--color-canvas);
  background-image: var(--caret-icon);
  background-position: center right 0.9em;
  background-repeat: no-repeat;
  background-size: 0.5em;
  border: 1px solid var(--color-ink-light);
  border-radius: 99rem;
  color: var(--color-ink);
  cursor: pointer;
  font-family: var(--font-base);
  font-size: var(--text-x-small);
  font-weight: 500;
  inset-inline-end: 0;
  line-height: 1.15lh;
  margin: 0.75ch 0.75ch 0 0;
  padding-inline: 1.5ch 1.8em;
  text-align: start;
}

.dark .lexxy-code-language-picker {
  --caret-icon: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m12 19.5c-.7 0-1.3-.3-1.7-.8l-9.8-11.1c-.7-.8-.6-1.9.2-2.6.8-.6 1.9-.6 2.5.2l8.6 9.8c0 .1.2.1.4 0l8.6-9.8c.7-.8 1.8-.9 2.6-.2s.9 1.8.2 2.6l-9.8 11.1c-.4.5-1.1.8-1.7.8z' fill='%23e5e7eb'/%3E%3C/svg%3E");
}

.lexxy-code-language-picker option {
  background-color: var(--color-canvas);
  color: var(--color-ink);
}

/* Toolbar
/* ---------------------------------------------------------------------------- */

lexxy-toolbar {
  --lexxy-toolbar-icon-size: 1em;

  background-color: var(--color-canvas);
  border-block-end: 1px solid var(--color-ink-light);
  color: var(--color-ink);
  display: flex;
  font-size: inherit;
  margin: 0;
  max-inline-size: 100%;
  padding: 0.2em 0;
  position: relative;
  position: sticky;
  inset-block-start: 0;
  z-index: 10;
}

.lexxy-editor__toolbar-button {
  --toolbar-button-size: 44px;

  appearance: none;
  aspect-ratio: 1;
  background-color: transparent;
  block-size: var(--toolbar-button-size);
  border: none;
  border-radius: 0.2em;
  color: currentColor;
  cursor: pointer;
  display: grid;
  font-size: inherit;
  place-items: center;
}

.lexxy-editor__toolbar-button:is(:focus, :hover) {
  background-color: var(--color-ink-lighter);
  box-shadow: none;
}

.lexxy-editor__toolbar-button:is(:active),
.lexxy-editor__toolbar-button[aria-pressed="true"] {
  background-color: var(--color-selected);
}

.lexxy-editor__toolbar-button svg {
  -webkit-touch-callout: none;
  block-size: var(--lexxy-toolbar-icon-size);
  fill: currentColor;
  grid-area: 1/1;
  inline-size: var(--lexxy-toolbar-icon-size);
  user-select: none;
}

@media (min-width: 640px) {
  .lexxy-editor__toolbar-button {
    --toolbar-button-size: 2em;
  }
}

.lexxy-editor__toolbar-overflow-menu {
  background-color: var(--color-canvas);
  border-radius: 0.5ch;
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  inset-inline-end: 0;
  padding: 4px;
  position: absolute;
  z-index: 1;
}

.lexxy-editor__toolbar-spacer {
  flex: 1;
}

/* Dropdowns
/* ---------------------------------------------------------------------------- */

.lexxy-editor__toolbar-dropdown-content {
  --lexxy-dropdown-padding: 0.75rem;
  --lexxy-dropdown-btn-size: 2rem;

  background-color: var(--color-canvas);
  border: 1px solid var(--color-ink-lighter);
  border-radius: 0.5em;
  box-shadow: var(--shadow);
  color: var(--color-ink);
  font-size: var(--text-small);
  padding: var(--lexxy-dropdown-padding);
  position: absolute;
  z-index: 1;
}

.lexxy-editor__toolbar-dropdown-content button {
  block-size: var(--lexxy-dropdown-btn-size);
}

.lexxy-editor__toolbar-dropdown-actions {
  display: flex;
  font-size: var(--text-x-small);
  flex: 1 1 0%;
  gap: var(--lexxy-dropdown-padding);
  margin-block-start: var(--lexxy-dropdown-padding);
}

.lexxy-editor__toolbar-dropdown-actions .btn {
  border-radius: 99rem;
  inline-size: 100%;
}

.lexxy-editor__toolbar-dropdown-actions .btn[type="submit"] {
  background-color: var(--color-link);
  color: var(--color-ink-inverted);
}

.lexxy-editor__toolbar-dropdown-actions span {
  inline-size: 100%;
}

/* Link dropdown */
lexxy-link-dropdown .input {
  min-inline-size: 30ch;
  background-color: var(--color-canvas);
  border: 1px solid var(--color-ink-light);
  border-radius: 0.375rem;
  color: var(--color-ink);
  padding: 0.5rem 0.75rem;
}

lexxy-link-dropdown .input:focus {
  outline: 2px solid var(--focus-ring-color);
  outline-offset: 1px;
}

lexxy-link-dropdown .input::placeholder {
  color: var(--color-ink-medium);
}

/* Highlight dropdown */
lexxy-highlight-dropdown {
  --gap: 0.5ch;
}

lexxy-highlight-dropdown [data-button-group] {
  display: flex;
  flex-direction: row;
  gap: var(--gap);
}

lexxy-highlight-dropdown [data-button-group] + [data-button-group] {
  margin-block-start: var(--gap);
}

@media (max-width: 639px) {
  lexxy-highlight-dropdown [data-button-group] {
    flex-wrap: wrap;
  }
}

.lexxy-highlight-button {
  --outline-color: rgb(31 41 55 / 0.2);

  appearance: none;
  background: var(--color-canvas);
  border: none;
  border-radius: 0.5ch;
  color: inherit;
  display: grid;
  font-weight: 500;
  inline-size: var(--lexxy-dropdown-btn-size, 2rem);
  place-content: center;
  position: relative;
  outline: none;
}

.lexxy-highlight-button:after {
  content: "Aa";
}

.lexxy-highlight-button:hover,
.lexxy-highlight-button[aria-pressed="true"] {
  box-shadow: 0 0 0 1px var(--color-canvas), 0 0 0 3px var(--outline-color);
}

.lexxy-highlight-button[aria-pressed="true"] {
  --outline-color: var(--color-link);
}

.lexxy-highlight-button[aria-pressed="true"]:after {
  content: "\2713";
}

.dark .lexxy-highlight-button {
  --outline-color: rgb(229 231 235 / 0.2);
}

.lexxy-editor__toolbar-dropdown-reset {
  background: var(--color-canvas);
  border: 1px solid var(--color-ink-light);
  border-radius: 99rem;
  inline-size: 100%;
  margin-block-start: var(--lexxy-dropdown-padding);
  color: var(--color-ink);
  padding: 0.5rem;
  cursor: pointer;
}

.lexxy-editor__toolbar-dropdown-reset:hover {
  background-color: var(--color-ink-lightest);
}

.lexxy-editor__toolbar-dropdown-reset[disabled] {
  display: none;
}

/* List styles - restore what Tailwind reset removes
/* ---------------------------------------------------------------------------- */

.lexxy-content ul,
.lexxy-editor ul,
lexxy-editor ul {
  list-style-type: disc;
  list-style-position: inside;
  padding-left: 1.5rem;
  margin: 0.5rem 0;
}

.lexxy-content ol,
.lexxy-editor ol,
lexxy-editor ol {
  list-style-type: decimal;
  list-style-position: inside;
  padding-left: 1.5rem;
  margin: 0.5rem 0;
}

.lexxy-content ul ul,
.lexxy-editor ul ul,
lexxy-editor ul ul {
  list-style-type: circle;
  padding-left: 1.5rem;
}

.lexxy-content ol ol,
.lexxy-editor ol ol,
lexxy-editor ol ol {
  list-style-type: lower-alpha;
  padding-left: 1.5rem;
}

.lexxy-content li,
.lexxy-editor li,
lexxy-editor li {
  margin: 0.25rem 0;
}

/* Nested lists */
.lexxy-content li > ul,
.lexxy-content li > ol,
.lexxy-editor li > ul,
.lexxy-editor li > ol,
lexxy-editor li > ul,
lexxy-editor li > ol {
  margin: 0.25rem 0 0.25rem 0;
}

/* Rich text content display
/* ---------------------------------------------------------------------------- */

.lexxy-content {
  color: var(--color-ink);
}

.lexxy-content p,
.lexxy-content span,
.lexxy-content div,
.lexxy-content strong,
.lexxy-content em,
.lexxy-content b,
.lexxy-content i,
.lexxy-content u,
.lexxy-content h1,
.lexxy-content h2,
.lexxy-content h3,
.lexxy-content h4,
.lexxy-content h5,
.lexxy-content h6,
.lexxy-content li,
.lexxy-content ol,
.lexxy-content ul,
.lexxy-content blockquote,
.lexxy-content pre,
.lexxy-content code {
  color: inherit;
}

/* Links in content */
.lexxy-content a {
  color: var(--color-link);
  text-decoration: underline;
}

.lexxy-content a:hover {
  text-decoration: none;
}

/* Blockquotes */
.lexxy-content blockquote,
.lexxy-editor blockquote,
lexxy-editor blockquote {
  border-left: 3px solid var(--color-ink-light);
  margin: 1rem 0;
  padding-left: 1rem;
  color: var(--color-ink-dark);
}

/* Code blocks */
.lexxy-content pre,
.lexxy-editor pre,
lexxy-editor pre {
  background-color: var(--color-ink-lightest);
  border-radius: 0.375rem;
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0;
}

.lexxy-content code,
.lexxy-editor code,
lexxy-editor code {
  font-family: ui-monospace, monospace;
  font-size: 0.875em;
}

.lexxy-content :not(pre) > code,
.lexxy-editor :not(pre) > code,
lexxy-editor :not(pre) > code {
  background-color: var(--color-ink-lightest);
  border-radius: 0.25rem;
  padding: 0.125rem 0.375rem;
}
