/* Uploaded images in rendered QuickText content (see RenderHtml.imageToHtml). Spaced like a
   paragraph. */

/* A landscape image is meant to fill the width, a portrait one half of it, and one in a table cell
   the cell's width */
div.qt-render div.qt-image,
div.qt-render div.qt-image-missing {
    margin: 0 0 var(--qt-paragraph-gap) 0;
}

div.qt-render div.qt-image {
    --qt-image-target: 100%;
}

div.qt-render div.qt-image-portrait {
    --qt-image-target: 50%;
}

/* On a phone, half the width would be too small */
div.qt-render.qt-context-mobile div.qt-image-portrait {
    --qt-image-target: 75%;
}

/* Selected specifically enough to override the mobile rule above */
div.qt-render td div.qt-image.qt-image-portrait,
div.qt-render th div.qt-image.qt-image-portrait {
    --qt-image-target: 100%;
}

/* The target width, unless that's more than twice the image's own width (--qt-image-width, set by
   RenderHtml), in which case its own width. The last term is hugely negative just when the target
   is more than twice the image's width, so max() then picks the image's width. Never wider than
   the target, so a large image is shrunk to fit. */
div.qt-render img.qt-image-img {
    display: block;
    margin: 0 auto;
    height: auto;
    width: min(var(--qt-image-target), max(var(--qt-image-width),
        calc(var(--qt-image-target) + (2 * var(--qt-image-width) - var(--qt-image-target)) * 1000)));
}

/* An image named which isn't in the user's catalog */
div.qt-render div.qt-image-missing {
    border: 1px dashed grey;
    color: grey;
    font-style: italic;
    padding: 0.5em;
    text-align: center;
}

/* On a slide, images directly in its body, or in its main or a sidebar column (see
   text-render-block.css), share the height the rest of its content leaves, each centred in its
   share, which SlideFitter sizes it to fit */
div.qt-render div.qt-slide-body:has(> div.qt-image),
div.qt-render div.qt-slide-main:has(> div.qt-image),
div.qt-render div.qt-sidebar-column:has(> div.qt-image) {
    display: flex;
    flex-direction: column;
}

div.qt-render div.qt-slide-body > div.qt-image,
div.qt-render div.qt-slide-main > div.qt-image,
div.qt-render div.qt-sidebar-column > div.qt-image {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Predefined glyphs (see RenderHtml.glyphToHtml), spaced like a paragraph and left-aligned */

/* A glyph's width is a percentage of the page's width, one of three chosen by a context class, like
   --qt-base-size (see text-render.css). A rendering style can set any of the three. */
div.qt-render {
    --qt-glyph-width-desktop: 5;
    --qt-glyph-width-mobile: 10;
    --qt-glyph-width-slides: 4;
    --qt-glyph-width: var(--qt-glyph-width-desktop);
    container-type: inline-size;
}

div.qt-render.qt-context-mobile {
    --qt-glyph-width: var(--qt-glyph-width-mobile);
}

div.qt-render.qt-context-slides {
    --qt-glyph-width: var(--qt-glyph-width-slides);
}

/* On a slide, the page is the slide itself */
div.qt-render div.qt-slide {
    container-type: inline-size;
}

div.qt-render div.qt-glyph {
    margin: 0 0 var(--qt-paragraph-gap) 0;
}

/* Sized in container query units, so it's relative to the page even inside a table cell. Glyphs
   are square, so their height is known before they load. */
div.qt-render img.qt-glyph-img {
    display: block;
    width: calc(var(--qt-glyph-width) * 1cqw);
    aspect-ratio: 1;
}

/* In a table cell, a glyph follows its column's alignment (see text-render-block.css). Children
   only, so in a nested table it follows its own cell rather than the outer one. */
div.qt-render .qt-table-center > div.qt-glyph > img.qt-glyph-img {
    margin: 0 auto;
}

div.qt-render .qt-table-right > div.qt-glyph > img.qt-glyph-img {
    margin-left: auto;
}

/* The Glyph Browser (see GlyphBrowser). The pane, header and body start as copies of the
   Gallery's. */
div.text-glyph-browser-pane {
    background-color: transparent;
    box-sizing: border-box;
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
}

div.text-glyph-browser-header {
    background-color: ghostwhite;
    border: 2px solid #111111;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px;
    border-bottom-color: navy;
}

span.text-glyph-browser-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: "Open Sans", "IBM Plex Sans", sans-serif;
    font-weight: bold;
    color: navy;
    font-size: 1.35em;
    padding-left: 8px;
}

/* Light in dark mode too, as the glyphs are drawn for a light background */
div.text-glyph-browser-body {
    flex: 1;
    min-height: 0;
    background-color: ghostwhite;
    border: 2px solid #111111;
    border-radius: 4px;
    padding: 16px;
    box-sizing: border-box;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

div.text-glyph-browser-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, 32px);
    gap: 16px;
}

/* As wide as its column (see div.text-glyph-browser-grid), which sets the glyphs' size */
div.text-glyph-browser-tile {
    aspect-ratio: 1;
    cursor: pointer;
}

/* The glyph under the pointer. An outline, so it doesn't move anything. */
div.text-glyph-browser-tile:hover {
    outline: 3px solid navy;
    outline-offset: 4px;
    border-radius: 4px;
}

img.text-glyph-browser-glyph {
    display: block;
    width: 100%;
    height: 100%;
}
