/*
 * The public gallery viewer.
 *
 * Deliberately small. This page has one job — show somebody else's workspace to a stranger who
 * arrived from a link — so everything on it is either the drawing or the few facts that make the
 * drawing mean something: who made it, what it is, and what you are allowed to do with it.
 *
 * The canvas colours are NOT here. They live in canvas-theme.css, shared with the editor.
 */

@import url('canvas-theme.css');

.gallery-view {
    --gallery-bg: #141625;
    --gallery-panel: #1E2030;
    --gallery-border: rgba(255, 255, 255, 0.08);
    --gallery-text: #E5E7EB;
    --gallery-muted: #9CA3AF;

    display: flex;
    flex-direction: column;
    /* The header is fixed-height chrome; the canvas takes the rest. Viewport units rather than a
       percentage chain, because every ancestor would otherwise need an explicit height. */
    height: calc(100vh - 64px);
    background: var(--gallery-bg);
    color: var(--gallery-text);
}

/* ----------------------------------------------------------------- header */

.gallery-view-bar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem 0.35rem;
}

.gallery-view-title {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1.2;
    /* Another user's title, of unknown length, on one line. Ellipsis rather than wrapping, so a
       pathological title cannot push the canvas off the screen. */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60vw;
}

.gallery-view-meta {
    margin: 0.25rem 0 0;
    font-size: 0.85rem;
    color: var(--gallery-muted);
}

.gallery-view-meta strong {
    color: var(--gallery-text);
    font-weight: 500;
}

.gallery-dot {
    margin: 0 0.5rem;
    opacity: 0.5;
}

.gallery-license,
.gallery-category {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border: 1px solid var(--gallery-border);
    border-radius: 999px;
    font-size: 0.75rem;
}

.gallery-view-summary {
    margin: 0;
    padding: 0 1.5rem 0.75rem;
    max-width: 70ch;
    font-size: 0.95rem;
    color: var(--gallery-muted);
}

/* ---------------------------------------------------------------- actions */

.gallery-btn {
    padding: 0.4rem 0.85rem;
    border: 1px solid var(--gallery-border);
    border-radius: 8px;
    background: transparent;
    color: var(--gallery-text);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.gallery-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.16);
}

.gallery-btn-icon {
    padding: 0.1rem 0.5rem;
    font-size: 1.1rem;
    line-height: 1;
}

/* The one thing this page is asking the visitor to do. Everything else on it is chrome. */
.gallery-btn-primary {
    border-color: transparent;
    background: #3B82F6;
    color: #fff;
    font-weight: 500;
}

.gallery-btn-primary:hover {
    background: #2563EB;
    border-color: transparent;
}

.gallery-btn-primary:disabled {
    opacity: 0.6;
    cursor: default;
}

.gallery-view-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* ------------------------------------------------------------------ stage */

.gallery-stage {
    position: relative;
    display: flex;
    flex: 1;
    min-height: 0;   /* without this the canvas host refuses to shrink and overflows the page */
    border-top: 1px solid var(--gallery-border);
}

.gallery-canvas-host {
    position: relative;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

#galleryCanvas {
    display: block;
    width: 100%;
    height: 100%;
    /* Grab, not text: this surface is a camera, and an I-beam over a drawing invites a selection
       that will never happen. */
    cursor: grab;
}

#galleryCanvas:active {
    cursor: grabbing;
}

.gallery-status {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gallery-muted);
    font-size: 0.95rem;
    pointer-events: none;
}

.gallery-status[hidden] {
    display: none;
}

/* -------------------------------------------------------------- inspector */

/*
 * Width is a clamp, not a constant.
 *
 * It was `min(420px, 40vw)`, which reads as responsive and is not: past 1050px wide the `min`
 * always picks 420px, so a 2000px screen got the same narrow column as a laptop while half the
 * canvas sat empty beside it — and the code wrapped constantly inside it. `clamp` grows with the
 * viewport instead, and the ceiling is there because a line of code past ~90 characters is harder
 * to read, not easier.
 *
 * `flex: none` so the panel keeps whatever width it is given: it sits next to a `flex: 1` canvas
 * host, which would otherwise negotiate the width back off it the moment the drag set one.
 */
.gallery-inspector {
    position: relative;
    display: flex;
    flex: none;
    flex-direction: column;
    width: clamp(360px, 34vw, 760px);
    border-left: 1px solid var(--gallery-border);
    background: var(--gallery-panel);
}

/*
 * The drag handle, sitting ON the border rather than beside it — a resizer that takes up layout
 * width is a strip of dead space you notice every time you do not want to resize.
 */
.gallery-inspector-resizer {
    position: absolute;
    top: 0;
    bottom: 0;
    left: -3px;
    width: 7px;
    z-index: 2;
    cursor: col-resize;
    /* Wider than it looks: the visible line is 1px, and a 1px drag target is a fight. */
    background: transparent;
    transition: background 0.15s ease;
}

.gallery-inspector-resizer:hover,
.gallery-inspector-resizer:focus-visible,
.gallery-inspector.is-resizing .gallery-inspector-resizer {
    background: rgba(59, 130, 246, 0.55);
    outline: none;
}

/*
 * While dragging, the pointer is over the CANVAS as often as not, and that canvas has its own
 * pan handler. Turning off pointer events everywhere for the duration is what stops a resize
 * from also dragging the drawing behind it.
 */
.gallery-stage.is-resizing * {
    pointer-events: none;
    user-select: none;
}

.gallery-stage.is-resizing .gallery-inspector-resizer {
    pointer-events: auto;
}

.gallery-inspector[hidden] {
    display: none;
}

.gallery-inspector-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--gallery-border);
}

.gallery-inspector-type {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gallery-muted);
}

.gallery-inspector-label {
    margin: 0;
    padding: 0.75rem 0.9rem 0.35rem;
    font-size: 1rem;
    font-weight: 600;
    word-break: break-word;
}

.gallery-inspector-code {
    flex: 1;
    min-height: 0;
    margin: 0;
    padding: 0.75rem 0.9rem 1rem;
    overflow: auto;
    font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--gallery-text);
    /* pre-wrap, not pre: a long minified line would otherwise scroll this panel sideways forever
       and take the page's horizontal scrollbar with it. */
    white-space: pre-wrap;
    word-break: break-word;
    tab-size: 4;
}

/* ------------------------------------------------- highlighted code --
 *
 * Written by wwwroot/js/code-highlight.js, one `.chl-line` per line of source, each holding one
 * span per coloured run. The classes are the only thing that file decides; the characters inside
 * them are always set with textContent, because this is code a stranger published.
 *
 * Scoped to `.is-code` so a schedule expression or a file name — which are shown here too — do
 * not get line numbers they have no lines for.
 *
 * `code.is-code`, not `.gallery-inspector-code.is-code`: the two classes sit on DIFFERENT
 * elements — the layout class on the <pre>, the marker on the <code> inside it — so a compound
 * selector matches nothing at all and every line runs into the one before it.
 */
.gallery-inspector-code code.is-code {
    display: block;
    counter-reset: chl-line;
    /* Room for the numbers, which are pulled into it by the negative margin below. */
    padding-left: 3.1rem;
}

.gallery-inspector-code code.is-code .chl-line {
    display: block;
    counter-increment: chl-line;
    /* An empty line still has to occupy one, or its number lands on the next one's text. */
    min-height: 1.5em;
    /*
     * Hanging indent, so a line that wraps is obviously a continuation rather than a new
     * statement. The two cancel out on the first line — where the negative indent also pulls the
     * number back into place — and only the wrapped remainder is pushed in.
     */
    padding-left: 2ch;
    text-indent: -2ch;
}

.gallery-inspector-code code.is-code .chl-line::before {
    content: counter(chl-line);
    display: inline-block;
    width: 2.2rem;
    margin-left: -3.1rem;
    margin-right: 0.9rem;
    text-align: right;
    color: var(--gallery-muted);
    /* The numbers are furniture: they must never be picked up by a copy of the code. */
    user-select: none;
    -webkit-user-select: none;
}

/*
 * The palette. Deliberately close to the canvas's own accents rather than a stock editor theme —
 * this panel sits beside the drawing, and two unrelated colour schemes on one screen read as two
 * products.
 */
.chl-comment { color: #6b7488; font-style: italic; }
.chl-string { color: #7ee0a8; }
.chl-number { color: #f0b36b; }
.chl-keyword { color: #c792ea; }
.chl-literal { color: #f0b36b; }
.chl-global { color: #5fb3f0; }
.chl-fn { color: #7dd3fc; }
.chl-property { color: #cbd5e1; }
.chl-key { color: #5fb3f0; }

/* =========================================================== the listing ==
 *
 * Prefixed gx- so nothing here can collide with the viewer's rules above: the two pages share a
 * stylesheet because they are one feature, not because they are one layout.
 */

/*
 * The site's body has no background of its own — Bootstrap's white shows through. The viewer
 * paints its own dark ground and the listing has to as well, or its text is light grey on white.
 * Full-bleed wrapper for the colour, centred column inside it for the measure: painting the
 * background on the centred column instead leaves white gutters down both sides.
 */
.gx-page {
    background: #141625;
    /* Fills the screen when there is little to list, so a young gallery does not end in a band of
       white halfway down the page. */
    min-height: calc(100vh - 64px);
}

.gx {
    max-width: 1180px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
    color: #E5E7EB;
}

.gx-title {
    margin: 0;
    font-size: 2rem;
    font-weight: 600;
}

.gx-lede {
    margin: 0.6rem 0 0;
    max-width: 62ch;
    color: #9CA3AF;
    line-height: 1.55;
}

/* ---------------------------------------------------------------- filters */

.gx-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 1.75rem 0 2rem;
}

.gx-filter {
    padding: 0.3rem 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    color: #9CA3AF;
    font-size: 0.82rem;
    text-decoration: none;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.gx-filter:hover {
    color: #E5E7EB;
    border-color: rgba(255, 255, 255, 0.22);
}

.gx-filter.is-on {
    background: rgba(59, 130, 246, 0.14);
    border-color: rgba(59, 130, 246, 0.5);
    color: #BFDBFE;
}

/* ------------------------------------------------------------------ rails */

.gx-rail {
    margin-bottom: 2.75rem;
}

.gx-rail-head {
    margin-bottom: 0.9rem;
}

.gx-rail-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}

.gx-rail-blurb {
    margin: 0.15rem 0 0;
    font-size: 0.85rem;
    color: #6B7280;
}

.gx-grid {
    display: grid;
    /* auto-fill, not auto-fit: with three cards on a wide screen, auto-fit stretches them to the
       full width and a rail of three looks like a rail of three enormous things. */
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0.9rem;
}

/* ------------------------------------------------------------------ cards */

.gx-card {
    display: flex;
    flex-direction: column;
    min-height: 150px;
    padding: 0.9rem 1rem 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    background: #1E2030;
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.gx-card:hover {
    border-color: rgba(59, 130, 246, 0.45);
    transform: translateY(-2px);
    color: inherit;
}

.gx-card-cat {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #6B7280;
}

.gx-card-title {
    margin: 0.35rem 0 0;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
}

.gx-card-summary {
    margin: 0.4rem 0 0;
    font-size: 0.84rem;
    line-height: 1.45;
    color: #9CA3AF;
    /* Three lines, then stop. Summaries are one line by design, but this is another user's text
       and a card that grows to fit it breaks the grid for everything beside it. */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gx-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: auto;
    padding-top: 0.7rem;
    font-size: 0.78rem;
    color: #6B7280;
}

.gx-card-author {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gx-card-forks {
    flex-shrink: 0;
    color: #9CA3AF;
}

/* ------------------------------------------------------------------ empty */

.gx-empty {
    padding: 3rem 0;
    max-width: 56ch;
}

.gx-empty h2 {
    margin: 0 0 0.5rem;
    font-size: 1.15rem;
    font-weight: 600;
}

.gx-empty p {
    margin: 0;
    color: #9CA3AF;
    line-height: 1.55;
}

/* ----------------------------------------------------------------- mobile */

@media (max-width: 768px) {
    .gallery-stage {
        flex-direction: column;
    }

    .gallery-inspector {
        width: 100%;
        max-height: 45%;
        border-left: none;
        border-top: 1px solid var(--gallery-border);
    }

    .gallery-view-title {
        max-width: 100%;
        white-space: normal;
    }
}

/*
 * "Forking this gets you the code, not the rows."
 *
 * A note rather than a warning: nothing here is wrong, and a red banner over somebody's published
 * work would read as a defect report on it. Tinted like the DB badge in the template picker, since
 * they are saying the same thing in two places.
 */
.gallery-db-note {
    margin: 0 1.5rem 0.75rem;
    padding: 0.55rem 0.8rem;
    max-width: 70ch;
    border: 1px solid rgba(99, 102, 241, 0.35);
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.08);
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--gallery-muted);
}

.gallery-db-note strong { color: #a5b4fc; }
.gallery-db-note a { color: #a5b4fc; }

/* ---- Report -----------------------------------------------------------------------------------
   Understated by design. This button sits beside Fork, which is the page's actual funnel, and a
   loud report control next to it would compete with the thing the gallery exists to do. It only
   needs to be findable by somebody already looking for it. */

.gallery-btn-quiet {
    opacity: 0.62;
    font-weight: 400;
}

.gallery-btn-quiet:hover {
    opacity: 1;
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.4);
}

.gallery-btn-danger {
    background: #dc2626;
    border-color: #dc2626;
    color: #fff;
}

.gallery-btn-danger:hover { background: #ef4444; border-color: #ef4444; }
.gallery-btn-danger[disabled] { opacity: 0.6; cursor: default; }

.gallery-report-dialog {
    width: min(30rem, calc(100vw - 2rem));
    padding: 1.4rem;
    border: 1px solid var(--canvas-border, #293548);
    border-radius: 14px;
    background: var(--canvas-surface, #151c28);
    color: var(--canvas-text, #e6edf5);
}

.gallery-report-dialog::backdrop { background: rgba(2, 6, 16, 0.62); }

.gallery-report-dialog h2 { margin: 0 0 0.4rem; font-size: 1.1rem; }

.gallery-report-lede {
    margin: 0 0 1rem;
    font-size: 0.875rem;
    opacity: 0.72;
    line-height: 1.5;
}

.gallery-report-dialog label {
    display: block;
    margin: 0.9rem 0 0.3rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.gallery-report-optional { font-weight: 400; opacity: 0.6; }

.gallery-report-dialog select,
.gallery-report-dialog textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--canvas-border, #293548);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    color: inherit;
    font: inherit;
    font-size: 0.9rem;
}

.gallery-report-dialog textarea { resize: vertical; }

.gallery-report-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1.2rem;
}

.gallery-report-result {
    margin: 0.9rem 0 0;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    font-size: 0.875rem;
    line-height: 1.5;
}

.gallery-report-result.is-ok { background: rgba(52, 211, 153, 0.14); color: #34d399; }
.gallery-report-result.is-error { background: rgba(248, 113, 113, 0.14); color: #f87171; }
