@layer components {
  /* The box the slash list and the link field are placed in. */
  .visual-editor { position: relative; }
  .visual-editor-toolbar {
    position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 4px;
    border-bottom: 1px solid var(--border); background: var(--background);
  }
  .visual-editor-tool {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 32px; min-height: 32px;
    padding: 0 6px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--foreground);
    font: inherit; cursor: pointer;
  }
  .visual-editor-tool:is(:hover, :active) { background: var(--muted); }
  /* The pressed state carries an underline, not only a tint. */
  .visual-editor-tool[aria-pressed="true"] {
    background: color-mix(in oklch, var(--primary) 14%, transparent); box-shadow: inset 0 -2px 0 var(--primary);
  }
  .visual-editor-tool[aria-disabled="true"] { color: light-dark(var(--muted-foreground), oklch(0.55 0 0)); cursor: default; }
  .visual-editor-tool[aria-disabled="true"]:is(:hover, :active) { background: transparent; }
  .visual-editor-tool:focus-visible, .visual-editor-menu-item:focus-visible { outline: 2px solid var(--jx-accent); outline-offset: 1px; }
  .visual-editor-style { min-width: 104px; justify-content: space-between; font-size: 13px; }
  .visual-editor-separator { flex: none; width: 1px; height: 20px; margin-inline: 4px; background: var(--border); }
  .visual-editor-undo { margin-left: auto; }
  /* The groups only carry hiding: their tools stay the bar's own items. */
  .visual-editor-group { display: contents; }
  /* Beats the display of tools, menu items and groups, which would show what is hidden. */
  .visual-editor-toolbar [hidden] { display: none; }
  /* Fitted by script: one line, nothing shrinks (what does not fit moves to « Plus »); the bar never widens its parent. */
  .visual-editor-toolbar[data-overflow-ready] { flex-wrap: nowrap; contain: inline-size; }
  .visual-editor-toolbar[data-overflow-ready] > *, .visual-editor-toolbar[data-overflow-ready] .visual-editor-group > * {
    flex: none; white-space: nowrap;
  }
  .visual-editor-tool--labelled { padding: 0 8px; font-size: 13px; }
  .visual-editor-state { padding-inline: 8px; color: var(--muted-foreground); font-size: 13px; }

  .visual-editor-menu, .visual-editor-slash, .visual-editor-link {
    position: absolute; z-index: 20; min-width: 200px; padding: 4px; border: 1px solid var(--border);
    border-radius: var(--radius-md); background: var(--popover); color: var(--popover-foreground);
    box-shadow: var(--shadow-sm); font-size: 14px;
  }
  .visual-editor-menu { top: 100%; left: 4px; overflow-y: auto; }
  .visual-editor-menu:not([hidden]), .visual-editor-slash:not([hidden]) { display: flex; flex-direction: column; }
  .visual-editor-menu-item, .visual-editor-slash-option {
    display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 8px; border: 0;
    border-radius: var(--radius-sm); background: transparent; color: inherit; font: inherit; text-align: left;
    cursor: pointer;
  }
  .visual-editor-menu-item:is(:hover, :active), .visual-editor-slash-option:is(:hover, :active) { background: var(--muted); }
  /* The active option also carries a bar on its left edge. */
  .visual-editor-slash-option[aria-selected="true"], .visual-editor-menu-item:focus-visible,
  .visual-editor-menu-item[aria-checked="true"] { background: var(--muted); box-shadow: inset 2px 0 0 var(--primary); }
  /* The checked twin carries a tick: the tint and the left bar are also the focus's. */
  .visual-editor-menu-item[role="menuitemcheckbox"][aria-checked="true"]::after { content: "✓" / ""; margin-left: auto; }
  /* Nothing from the bar moved here: no separator, no table group. */
  .visual-editor-menu:not(:has([data-overflow-mirror]:not([hidden]))) .visual-editor-menu-separator { display: none; }
  .visual-editor-menu [role="group"][data-visual-editor-table]:not(:has([data-overflow-mirror]:not([hidden]))) { display: none; }
  .visual-editor-menu-separator { height: 1px; margin: 4px 0; border: 0; background: var(--border); }
  .visual-editor-slash-option kbd { margin-left: auto; color: var(--muted-foreground); font: 13px var(--font-mono); }
  /* Each style is shown in its own look. */
  .visual-editor-menu-item--heading2 { font: 600 16px var(--font-heading); }
  .visual-editor-menu-item--heading3 { font: 600 14px var(--font-heading); }

  /* The « A » carries the current text color as a 3 px underline (the foreground when there is none). */
  .visual-editor-color-glyph {
    font-weight: 700; font-size: 14px; line-height: 1; padding-bottom: 1px; border-bottom: 3px solid var(--foreground);
  }
  .visual-editor-color[data-color="gray"] .visual-editor-color-glyph { border-bottom-color: var(--doc-color-gray); }
  .visual-editor-color[data-color="brown"] .visual-editor-color-glyph { border-bottom-color: var(--doc-color-brown); }
  .visual-editor-color[data-color="orange"] .visual-editor-color-glyph { border-bottom-color: var(--doc-color-orange); }
  .visual-editor-color[data-color="yellow"] .visual-editor-color-glyph { border-bottom-color: var(--doc-color-yellow); }
  .visual-editor-color[data-color="green"] .visual-editor-color-glyph { border-bottom-color: var(--doc-color-green); }
  .visual-editor-color[data-color="blue"] .visual-editor-color-glyph { border-bottom-color: var(--doc-color-blue); }
  .visual-editor-color[data-color="purple"] .visual-editor-color-glyph { border-bottom-color: var(--doc-color-purple); }
  .visual-editor-color[data-color="pink"] .visual-editor-color-glyph { border-bottom-color: var(--doc-color-pink); }
  .visual-editor-color[data-color="red"] .visual-editor-color-glyph { border-bottom-color: var(--doc-color-red); }
  .visual-editor-color[aria-expanded="true"] { background: var(--muted); }

  /* Two groups of ten swatches, one under the other in a 400 px panel; the menu itself never scrolls sideways. */
  .visual-editor-menu.visual-editor-color-menu:not([hidden]) { width: 400px; max-width: calc(100vw - 16px); padding: 10px; gap: 8px; }
  .visual-editor-color-heading, .visual-editor-color-hint { margin: 0 4px; }
  .visual-editor-color-heading {
    color: var(--muted-foreground); font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  }
  .visual-editor-color-hint { padding-top: 8px; border-top: 1px solid var(--border); color: var(--muted-foreground); font-size: 13px; }
  .visual-editor-swatches { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px; }
  .visual-editor-swatch {
    position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; height: 32px; padding: 0;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card); color: var(--foreground);
    font: 700 14px/1 var(--font-sans); cursor: pointer;
  }
  .visual-editor-swatch > span { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; padding: 0; }
  .visual-editor-swatch:is(:hover, :active) { border-color: var(--foreground); }
  .visual-editor-swatch:focus-visible { outline: 2px solid var(--jx-accent); outline-offset: 1px; }
  /* Checked: a ring and a drawn tick in the corner, never the color alone. */
  .visual-editor-swatch[aria-checked="true"] { outline: 2px solid var(--primary); outline-offset: 1px; }
  .visual-editor-swatch[aria-checked="true"]::after {
    content: "✓" / ""; position: absolute; right: 1px; bottom: 0; display: grid; place-items: center; min-width: 12px;
    border-radius: var(--radius-sm); background: var(--background); color: var(--foreground); font-size: 13px; line-height: 12px;
  }
  /* The first background swatch (none) shows a small cross, not words. */
  .visual-editor-swatch--background:first-child::before {
    content: "×" / ""; position: absolute; inset: 0; display: grid; place-items: center; font-size: 18px; color: var(--muted-foreground);
  }

  .visual-editor-link { display: flex; flex-direction: column; gap: 6px; width: 320px; max-width: calc(100vw - 32px); padding: 8px; }
  .visual-editor-link[hidden] { display: none; }
  .visual-editor-link-row { display: flex; align-items: center; gap: 6px; }
  .visual-editor-link-row[hidden] { display: none; }
  .visual-editor-link-row input { flex: 1; min-width: 0; }
  .visual-editor-link :is(input, select, .button) { min-height: 32px; }
  .visual-editor-link-error { margin: 0; color: var(--destructive); font-size: 13px; }
  /* A sign before the text, so the error is not told by its colour alone. */
  .visual-editor-link-error::before { content: "⚠ " / ""; }

  /* Preview only: shows the closed parts side by side, without a script to open them. */
  .visual-editor-preview--open :is(.visual-editor-menu, .visual-editor-slash, .visual-editor-link)[hidden] {
    position: static; display: flex; flex-direction: column; margin: 8px 4px;
  }

  /* A finger needs 44 px, and a 1px halo: rounded corners and half-pixel boxes would otherwise miss a 44 px probe. */
  @media (pointer: coarse) {
    .visual-editor-tool, .visual-editor-menu-item {
      position: relative; min-width: var(--tap); min-height: var(--tap);
    }
    :is(.visual-editor-tool, .visual-editor-menu-item, .visual-editor-slash-option)::before {
      content: ""; position: absolute; inset: -1px;
    }
    /* Kept: without it the touch probe misses corners of « Plus » and the tools (sub-pixel offsets). */
    .visual-editor-menu, .visual-editor-slash { margin-top: 1px; gap: 2px; }
    .visual-editor-slash-option { position: relative; min-height: var(--tap); }
    .visual-editor-swatch { height: var(--tap); }
    .visual-editor-menu.visual-editor-color-menu:not([hidden]) { width: 540px; }
    .visual-editor-link :is(input, select, .button, a) { min-height: var(--tap); }
    .visual-editor-link a { display: inline-flex; align-items: center; padding-inline: 8px; }
  }
}
