@font-face {
  font-family: 'LSBSymbolWeb';
  src:
    url('https://s3.amazonaws.com/lsb-production/fonts/LSBSymbol.eot?')
      format('eot'),
    url('https://s3.amazonaws.com/lsb-production/fonts/LSBSymbol.woff')
      format('woff'),
    url('https://s3.amazonaws.com/lsb-production/fonts/LSBSymbol.ttf')
      format('truetype'),
    url('https://s3.amazonaws.com/lsb-production/fonts/LSBSymbol.svg#LSBSymbol')
      format('svg');
}

:root {
  --lsml-button-background: #f4f4f4;
  --lsml-button-active-background: #e0e0e0;
  --lsml-button-border: 1px solid #e0e0e0;
  --lsml-button-foreground: #000;
  --lsml-button-border-radius: 5px;
  --lsml-editor-padding: 0.6em;
  --lsml-focus-border-color: hsl(218, 81.8%, 56.9%);
  --lsml-focus-inner-shadow: 2px 2px 3px hsla(0, 0%, 0%, 0.1) inset;
}

@media (prefers-color-scheme: dark) {
  :root {
    --lsml-button-background: #333;
    --lsml-button-active-background: #666;
    --lsml-button-border: 1px solid #666;
    --lsml-button-foreground: #fff;
  }
}

/* =================
 * Editor
 * ================= */

.__lsml-editor_toolbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  row-gap: 0.25rem;
}

.__lsml-editor_control-group {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
}

.__lsml-editor_select,
.__lsml-editor_text-input {
  height: 2rem;
  line-height: 1.25rem;
  padding: 0.25rem;
}

.__lsml-editor_separator {
  display: block;
  margin-left: 0.25rem;
  margin-right: 0.25rem;
  height: 2rem;
  width: 1px;
  border-left: var(--lsml-button-border);
}

.__lsml-editor_button {
  display: block;
  margin: 0;
  padding: 0;

  .__lsml-editor_toggle-input {
    display: none;

    & + button {
      display: block;
      cursor: pointer;
      margin: 0;
      padding: calc(0.25rem - 1px);
      width: 2rem;
      height: 2rem;
      color: var(--lsml-button-foreground);
      background-color: var(--lsml-button-background);
      border: var(--lsml-button-border);
      border-radius: 0;

      & > svg {
        display: block;
        width: 1.5rem;
        height: 1.5rem;

        & text:not([fill]),
        & path:not([fill]),
        & rect:not([fill]) {
          fill: var(--lsml-button-foreground);
        }
      }
    }

    &:checked + button {
      background-color: var(--lsml-button-active-background);
    }
  }

  & > button {
    display: block;
    cursor: pointer;
    margin: 0;
    padding: calc(0.25rem - 1px);
    width: 2rem;
    height: 2rem;
    color: var(--lsml-button-foreground);
    background-color: var(--lsml-button-background);
    border: var(--lsml-button-border);
    border-radius: 0;

    & > svg {
      display: block;
      width: 1.5rem;
      height: 1.5rem;

      & text:not([fill]),
      & path:not([fill]),
      & rect:not([fill]) {
        fill: var(--lsml-button-foreground);
      }
    }
  }

  &:first-of-type {
    & button {
      border-top-left-radius: var(--lsml-button-border-radius);
      border-bottom-left-radius: var(--lsml-button-border-radius);
    }
  }

  &:last-of-type {
    & button {
      border-top-right-radius: var(--lsml-button-border-radius);
      border-bottom-right-radius: var(--lsml-button-border-radius);
    }
  }
}

/* =================
 * Editable area (a Lexxy editor; Lexxy's own theme isn't used)
 * ================= */

/* The editable area is the editor element's flex item, as CKEditor's was, so a
   host that makes .__lsml-editor a fixed-height flex column gets an editable
   area that fills what the toolbar leaves and scrolls; the wrappers between
   them would otherwise size to the content. */
.__lsml-editor_editor,
.__lsml-editor lexxy-editor {
  display: contents;
}

.__lsml-editor .lexxy-editor__content {
  flex-grow: 1;

  /* so that Firefox won't expand this div to the height of its content
     but will instead limit it to the height of its container. */
  flex-basis: 0;

  overflow: auto;
  margin: 0.25rem 0;
  padding: 0 var(--lsml-editor-padding);
  border: var(--lsml-button-border);
  border-radius: 2px;
  outline: none;

  &:focus {
    border: 1px solid var(--lsml-focus-border-color);
    box-shadow: var(--lsml-focus-inner-shadow);
  }

  /* Blocks and inline elements selected whole (engravings, crosses, …) */
  .lsml-node-selected {
    background-color: Highlight;
    outline: 3px solid var(--lsml-focus-border-color);
  }

  img.lsml-engraving {
    display: block;
    margin: 0;
  }

  /* Poetry is not context-sensitive in the editor, and should always be indented */
  p.poetry {
    margin-left: 2em;
  }

  div.lsb-responsorial {
    display: flex;
    flex-direction: row;

    & > .lsb-symbol:first-child {
      flex-shrink: 0;
    }

    & > .speaker {
      width: 1.5in;
      font-family: 'Times New Roman', Times, serif;
    }

    & > .part {
      flex-grow: 1;
    }

    &.responsorial-icon-C {
      .part p,
      .speaker {
        font-weight: bold;
      }
    }

    &.responsorial-icon-P {
      .part p,
      .speaker {
        font-weight: normal;
      }
    }

    &.responsorial-icon-R {
      .part p,
      .speaker {
        font-style: italic;
      }
    }

    p.poetry:first-child {
      padding-top: 0;
    }
    p.scripture-heading:first-child {
      padding-top: 0;
      font-weight: bold !important;
    }
  }

  .lsb-cross {
    display: inline-block;
    font-family: LSBSymbolWeb;
  }

  .chant-mark {
    display: inline-block;
    color: #ff0000;
    white-space: pre;
  }

  .placeholder {
    display: inline-block;
    border-radius: var(--lsml-button-border-radius);

    & > .placeholder-name {
      display: inline-block;
      background: var(--lsml-button-background);
      padding: 0 0.5rem;
      border: var(--lsml-button-border);
      border-top-left-radius: var(--lsml-button-border-radius);
      border-bottom-left-radius: var(--lsml-button-border-radius);
    }

    & > .placeholder-fallback {
      display: inline-block;
      padding: 0 0.5rem;
      border: var(--lsml-button-border);
      border-left: none;
      border-top-right-radius: var(--lsml-button-border-radius);
      border-bottom-right-radius: var(--lsml-button-border-radius);
    }
  }

  /* A verse number is a span while editing (its marks are styled through their
     LSML classes, so host styles for .divine-name, .woc, etc. apply), so it
     needs the superscript a <sup> had natively. No specificity, so host
     styles win. */
  :where(.verse-number) {
    vertical-align: super;
    font-size: smaller;
  }

  /* Lexxy keeps hidden paragraphs beside blocks the caret can't otherwise
     reach; they show only once the caret is in one. Collapsed, they must stay
     displayed so they can still be clicked into, whatever a host's own
     `.hidden` (e.g. Tailwind's `display: none`) says; Lexxy's stylesheet,
     which this replaces, keeps them displayed too. */
  p.provisional-paragraph.hidden {
    display: block;
    block-size: 0.5ch;
    margin: 0;
    overflow: hidden;
  }

  /* Lexical's caret beside a block that isn't text (e.g. between engravings) */
  [data-lexical-cursor] {
    animation: __lsml-editor_blink 1s infinite;
    block-size: 1lh;
    border-inline-start: 1.5px solid currentColor;
  }
}

/* Screen-reader announcements from Lexxy */
.__lsml-editor :where(lexxy-live-region, .lexxy-fake-selection) {
  block-size: 1px;
  border: 0;
  clip-path: inset(50%);
  inline-size: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
}

@keyframes __lsml-editor_blink {
  50% {
    opacity: 0;
  }
}

.__lsml-editor_placeholder-form {
  padding: 1rem;
  border-radius: 4px;
  flex-direction: column;
  row-gap: 0.5rem;
}

.__lsml-editor_placeholder-form[open] {
  display: flex;

  & > h3 {
    font-weight: bold;
    font-size: 1.2rem;
  }
}

.__lsml-editor_placeholder-buttons {
  display: flex;
  flex-direction: row;
  column-gap: 1rem;
  justify-content: flex-end;

  .__lsml-editor_confirm-button {
    display: block;
    margin: 0;
    padding: 0.25rem 0.5rem;
    color: var(--lsml-button-foreground);
    background-color: var(--lsml-button-background);
    border: var(--lsml-button-border);
    border-radius: var(--lsml-button-border-radius);
    cursor: pointer;
  }
}

/* =================
 * Content
 * ================= */

.lsb-symbol {
  text-transform: none !important;
  font-family: LSBSymbolWeb;
}

/* =================
 * Popover-select
 * ================= */

.__lsml-editor_popover-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  height: 2rem;
  line-height: 1.25rem;
  padding: 0.25rem 0.5rem;
  color: var(--lsml-button-foreground);
  background-color: var(--lsml-button-background);
  border: var(--lsml-button-border);
  border-radius: var(--lsml-button-border-radius);
  cursor: pointer;
}

.__lsml-editor_popover-trigger[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.__lsml-editor_popover {
  position: absolute;
  margin: 0;
  padding: 0.25rem 0;
  background: var(--lsml-button-background);
  color: var(--lsml-button-foreground);
  border: var(--lsml-button-border);
  border-radius: var(--lsml-button-border-radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 12rem;
}

.__lsml-editor_popover-option {
  display: grid;
  grid-template-columns: 1.5rem 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}

.__lsml-editor_popover-option[data-active="true"],
.__lsml-editor_popover-option:hover {
  background-color: var(--lsml-button-active-background);
}

.__lsml-editor_popover-option[aria-selected="true"] {
  font-weight: bold;
}

.__lsml-editor_popover-icon {
  display: inline-block;
  text-align: center;
  width: 1.5rem;
}

/* When the editor is configured to hide symbols, also hide them in popover dropdowns. */
.__lsml-editor[data-lsml-editor-hide-symbols-value="true"] .__lsml-editor_popover-option {
  grid-template-columns: 1fr;
}
.__lsml-editor[data-lsml-editor-hide-symbols-value="true"] .__lsml-editor_popover-icon,
.__lsml-editor[data-lsml-editor-hide-symbols-value="true"] .__lsml-editor_popover-trigger .__lsml-editor_popover-icon {
  display: none;
}

/* =================
 * Custom-speaker form (rendered into the popover when custom_speakers: is set)
 * ================= */

.__lsml-editor_custom-speaker-form {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.75rem;
  min-width: 14rem;
}

.__lsml-editor_custom-speaker-form h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.__lsml-editor_custom-speaker-icons {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0 0 1rem;
  padding: 0;
  border: 0;
}

.__lsml-editor_custom-speaker-icons legend {
  font-size: 0.75rem;
  color: #6b6b6b;
  margin-bottom: 0.25rem;
  padding: 0;
}

@media (prefers-color-scheme: dark) {
  .__lsml-editor_custom-speaker-icons legend {
    color: #b0b0b0;
  }
}

.__lsml-editor_custom-speaker-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: var(--lsml-button-border);
  border-radius: var(--lsml-button-border-radius);
  background-color: var(--lsml-button-background);
  cursor: pointer;
  user-select: none;
}

.__lsml-editor_custom-speaker-icon input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.__lsml-editor_custom-speaker-icon:has(input[type="radio"]:checked) {
  background-color: var(--lsml-button-active-background);
  border-color: var(--lsml-button-foreground);
}

.__lsml-editor_custom-speaker-icon:has(input[type="radio"]:focus-visible) {
  outline: 2px solid Highlight;
  outline-offset: 2px;
}

.__lsml-editor_custom-speaker-speaker {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 1rem;
}

.__lsml-editor_custom-speaker-speaker-label {
  font-size: 0.75rem;
  color: #6b6b6b;
}

@media (prefers-color-scheme: dark) {
  .__lsml-editor_custom-speaker-speaker-label {
    color: #b0b0b0;
  }
}

.__lsml-editor_custom-speaker-speaker input[type="text"] {
  padding: 0.25rem 0.5rem;
  border: var(--lsml-button-border);
  border-radius: var(--lsml-button-border-radius);
  background-color: white;
  color: var(--lsml-button-foreground);
}

.__lsml-editor_custom-speaker-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.__lsml-editor_custom-speaker-buttons button {
  padding: 0.25rem 0.75rem;
  border: var(--lsml-button-border);
  border-radius: var(--lsml-button-border-radius);
  background-color: var(--lsml-button-background);
  color: var(--lsml-button-foreground);
  cursor: pointer;
}

.__lsml-editor_custom-speaker-buttons button[type="submit"] {
  background-color: var(--lsml-button-active-background);
}
