:root {
    --text-color: #c8c3bc;
    --bg-color-1: rgba(17, 18, 19, 1);
    --bg-color-2: rgba(22, 24, 25, 1);
    --bg-color-3: rgba(32, 35, 36, 1);
    --bg-color-4: rgba(50, 53, 54, 1);
    --border-color-default: #585858;
    --accent-color: #38b9ff;
    --motion-fast: 0.15s;
    --motion-ease: ease;
    --bg-color-primary: #0f31a1;
    --bg-color-primary-hov: #031d74;
    --bg-color-danger: #b62815;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* The scripts toggle the hidden attribute; a class with its own display must not win. */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color-1);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    font-family: Arial, sans-serif;
    color: var(--text-color);
}

.share-page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    text-align: center;
    padding: 6vh 1rem 1.5rem;
    width: 100%;
}

.share-header {
    margin-bottom: 20px;
}

.share-main {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: flex-start;
}

.share-logo {
    display: inline-block;
    line-height: 0;
}

/* A definite height, not max-height: inside the shrink-to-fit link a percentage
   max-width has nothing to resolve against and collapses the logo. */
.share-logo img {
    height: 80px;
    width: auto;
    transition: opacity 0.2s;
}

.share-logo:hover img {
    opacity: 0.8;
}

/* Pushed to the bottom edge, never into the content above it. */
.share-footer {
    margin-top: auto;
    padding-top: 2.5rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem 1.25rem;
}

.share-footer-link {
    color: var(--text-color);
    opacity: 0.55;
    text-decoration: none;
    font-size: 0.8em;
}

.share-footer-link:hover {
    opacity: 1;
    color: var(--accent-color);
}

.share-box {
    background-color: var(--bg-color-2);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
    margin: 0 auto;
    max-width: 410px;
    width: 100%;
}

.share-message {
    font-size: 1em;
}

.share-message:not(:last-child) {
    margin-bottom: 1.5rem;
}

.share-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.share-error {
    color: var(--bg-color-danger);
    font-size: 0.9em;
    margin-bottom: 1rem;
    display: none;
}

/* A shared image needs more room than a password box. */
.share-box-wide {
    max-width: 900px;
}

/* The file gets the height the header, the buttons and the footer leave over —
   the page then never scrolls, whatever the file is. */
.share-box-fill {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.share-box-fill .share-image {
    flex: 1 1 0;
    min-height: 140px;
    display: flex;
    overflow: hidden;
}

/* The viewer is excluded: its canvas is sized already and its overlays are
   positioned, not laid out. The AASX view lays itself out. */
.share-box-fill .share-image:not(.share-viewer):not(.share-aasx) > * {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
}

.share-box-fill .share-image > a {
    display: flex;
    align-items: center;
    justify-content: center;
}

.share-box-fill .share-image img,
.share-box-fill .share-video {
    max-height: 100%;
    max-width: 100%;
    width: auto;
    object-fit: contain;
}

.share-box-fill .share-code {
    max-height: none;
}

.share-box-fill .share-viewer {
    height: auto;
}

.share-image {
    background-color: var(--bg-color-1);
    border-radius: 6px;
    margin-bottom: 1rem;
    padding: 0.5rem;
}

.share-image img {
    max-width: 100%;
    max-height: 70vh;
    display: block;
    margin: 0 auto;
}

.share-video {
    max-width: 100%;
    max-height: 70vh;
    display: block;
    margin: 0 auto;
}

/* JSON is read, not skimmed — it gets a scroll box instead of the page. */
.share-code {
    max-height: 70vh;
    overflow: auto;
    margin: 0;
    padding: 0.5rem;
    text-align: left;
    font-size: 0.8rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.share-viewer {
    position: relative;
    height: 70vh;
    padding: 0;
    overflow: hidden;
}

.share-viewer:fullscreen {
    height: 100%;
    border-radius: 0;
}

.share-viewer canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.share-viewer-status {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    padding: 0 1rem;
}

.share-hint {
    font-size: 0.8em;
    opacity: 0.6;
    margin-bottom: 1rem;
}

.share-filename {
    word-break: break-all;
}

.share-input {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border-color-default);
    border-radius: 6px;
    background-color: var(--bg-color-3);
    color: var(--text-color);
    font-size: 1em;
    outline: none;
    margin-bottom: 1rem;
}

.share-input:focus {
    border-color: var(--accent-color);
}

.share-btn {
    display: block;
    box-sizing: border-box;
    text-align: center;
    text-decoration: none;
    width: 100%;
    padding: 0.65rem;
    border: none;
    border-radius: 6px;
    background-color: var(--bg-color-primary);
    color: #fff;
    font-size: 1em;
    cursor: pointer;
    transition: background-color var(--motion-fast) var(--motion-ease);
}

.share-btn:hover {
    background-color: var(--bg-color-primary-hov);
}

.share-btn:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.share-btn-secondary {
    background-color: var(--bg-color-3);
    border: 1px solid var(--border-color-default);
    color: var(--text-color);
}

.share-btn-secondary:hover {
    background-color: var(--bg-color-4);
}

.share-btn-copied {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.share-tool-icon {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.share-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}

.share-actions > * {
    flex: 0 0 auto;
    width: 9.5rem;
}

/* Buttons over the canvas, out of the way until the model is there. */
.share-viewer-tools {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.4rem;
}

.share-tool {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--border-color-default);
    border-radius: 6px;
    background-color: rgba(32, 35, 36, 0.85);
    color: var(--text-color);
    cursor: pointer;
    transition: background-color var(--motion-fast) var(--motion-ease),
        border-color var(--motion-fast) var(--motion-ease);
}

.share-tool:hover {
    background-color: var(--bg-color-4);
    border-color: var(--text-color);
}

.share-tool:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}


.share-image > a {
    display: block;
    color: inherit;
    text-decoration: none;
}

/* Only visible where the file actually has alpha. */
.share-image-alpha img {
    background-image: linear-gradient(45deg, var(--bg-color-3) 25%, transparent 25%),
        linear-gradient(-45deg, var(--bg-color-3) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--bg-color-3) 75%),
        linear-gradient(-45deg, transparent 75%, var(--bg-color-3) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.share-hint-touch {
    display: none;
}

@media (hover: none) {
    .share-hint-pointer {
        display: none;
    }

    .share-hint-touch {
        display: inline;
    }
}

/* An AASX package: header over a tree and a side column with 3D and details —
   the layout of AASX Package Explorer. */
.share-box-aasx {
    max-width: 1280px;
}

.share-aasx {
    position: relative;
    flex-direction: column;
    padding: 0;
    text-align: left;
}

.aasx-head {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.75rem;
    border-bottom: 1px solid var(--bg-color-3);
}

.aasx-thumb {
    flex: 0 0 auto;
    width: 72px;
    height: 72px;
    border-radius: 6px;
    background-color: var(--bg-color-2);
    overflow: hidden;
}

/* Scoped to .share-aasx to outrank the generic image rules of the share box. */
.share-aasx .aasx-thumb img {
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: contain;
}

.aasx-head-text {
    min-width: 0;
}

.aasx-title {
    font-weight: bold;
    font-size: 1.05em;
    overflow-wrap: anywhere;
}

.aasx-sub {
    font-size: 0.8em;
    opacity: 0.65;
    margin-top: 0.2rem;
    overflow-wrap: anywhere;
}

.aasx-body {
    flex: 1 1 0;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(220px, 2fr) 3fr;
}

.aasx-body-single {
    grid-template-columns: 1fr;
}

.aasx-tree,
.aasx-group {
    list-style: none;
    margin: 0;
    padding: 0;
}

.aasx-tree {
    overflow: auto;
    padding: 0.35rem 0;
    border-right: 1px solid var(--bg-color-3);
}

.aasx-item:focus {
    outline: none;
}

.aasx-item:focus-visible > .aasx-row {
    outline: 2px solid var(--accent-color);
    outline-offset: -2px;
}

.aasx-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem 0.6rem 0.2rem calc(0.4rem + var(--aasx-depth, 0) * 1rem);
    font-size: 0.85em;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--motion-fast) var(--motion-ease);
}

.aasx-row:hover {
    background-color: var(--bg-color-2);
}

.aasx-item[aria-selected="true"] > .aasx-row {
    background-color: var(--bg-color-3);
    box-shadow: inset 2px 0 0 var(--accent-color);
}

.aasx-item[aria-selected="true"] > .aasx-row > .aasx-badge {
    background-color: var(--bg-color-4);
}

.aasx-row-missing {
    opacity: 0.5;
}

.aasx-caret {
    flex: 0 0 auto;
    width: 1rem;
    height: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aasx-item[aria-expanded] > .aasx-row > .aasx-caret::before {
    content: "";
    border-style: solid;
    border-width: 4px 0 4px 6px;
    border-color: transparent transparent transparent currentColor;
    opacity: 0.7;
    transition: transform var(--motion-fast) var(--motion-ease);
}

.aasx-item[aria-expanded="true"] > .aasx-row > .aasx-caret::before {
    transform: rotate(90deg);
}

.aasx-badge {
    flex: 0 0 auto;
    padding: 0 0.3rem;
    border-radius: 4px;
    background-color: var(--bg-color-3);
    color: var(--accent-color);
    font-size: 0.75em;
    line-height: 1.5;
}

.aasx-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

.aasx-value {
    opacity: 0.6;
    overflow: hidden;
    text-overflow: ellipsis;
}

.aasx-value::before {
    content: "= ";
}

.aasx-side {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.aasx-stage {
    position: relative;
    flex: 1 1 0;
    min-height: 180px;
    border-bottom: 1px solid var(--bg-color-3);
    overflow: hidden;
    text-align: center;
}

.aasx-stage:fullscreen {
    background-color: var(--bg-color-1);
}

.aasx-stage canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.aasx-details {
    flex: 1 1 0;
    min-height: 0;
    overflow: auto;
    padding: 0.75rem;
}

.aasx-details-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: bold;
    margin-bottom: 0.75rem;
    overflow-wrap: anywhere;
}

.aasx-fields {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 0.35rem 0.9rem;
    margin: 0;
    font-size: 0.85em;
}

.aasx-fields dt {
    opacity: 0.6;
}

.aasx-fields dd {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.aasx-preview {
    margin-top: 0.9rem;
}

.share-aasx .aasx-preview img {
    display: block;
    margin: 0;
    max-width: 100%;
    max-height: 240px;
    border-radius: 6px;
    background-color: var(--bg-color-2);
}

.aasx-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.9rem;
}

.aasx-action {
    width: auto;
    padding: 0.4rem 0.8rem;
    font-size: 0.85em;
}

.aasx-note {
    margin: 0;
    opacity: 0.8;
}

/* Phones: the logo becomes a small mark in the corner, the file gets the screen. */
@media (max-width: 700px) {
    .share-page {
        padding: 0.9rem 0.75rem 1rem;
    }

    .share-header {
        text-align: left;
        margin-bottom: 0.9rem;
    }

    .share-logo img {
        height: 28px;
    }

    .share-box {
        padding: 1rem;
    }

    .share-viewer {
        height: 60vh;
    }

    .share-image img,
    .share-video,
    .share-code {
        max-height: 60vh;
    }

    /* Too narrow for columns: the page scrolls, each pane keeps a usable height. */
    .share-box-fill .share-aasx,
    .aasx-body,
    .aasx-details {
        flex: 0 0 auto;
    }

    .aasx-body {
        grid-template-columns: 1fr;
    }

    .aasx-tree {
        max-height: 45vh;
        border-right: none;
        border-bottom: 1px solid var(--bg-color-3);
    }

    .aasx-stage {
        flex: 0 0 auto;
        height: 45vh;
    }

    .share-footer {
        padding-top: 1.5rem;
        gap: 0.35rem 0.9rem;
    }
}

@media (max-width: 400px) {
    .share-message {
        font-size: 0.8em;
    }
}

/* Landscape on a phone: everything around the file gives up what it can. */
@media (max-height: 560px) {
    .share-page {
        padding-top: 0.6rem;
    }

    .share-header {
        margin-bottom: 0.5rem;
    }

    .share-logo img {
        height: 22px;
    }

    .share-box {
        padding: 0.75rem;
    }

    .share-box-fill .share-image {
        min-height: 90px;
    }

    .share-message:not(:last-child) {
        margin-bottom: 0.75rem;
    }

    .share-hint {
        margin-bottom: 0.5rem;
    }

    .share-footer {
        padding-top: 0.9rem;
    }
}

/* The /vr pairing code, read off a headset display from arm's length. */
.share-pair-code {
    font-family: "Courier New", monospace;
    font-size: 4rem;
    font-weight: bold;
    letter-spacing: 0.3em;
    padding-left: 0.3em; /* letter-spacing trails the last glyph too */
    color: var(--accent-color);
    margin-bottom: 1.5rem;
}

/* --- /vr: column of the pairing box and the "Recently opened" tiles ------- */
.share-stack {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.share-recent {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    text-align: left;
}

.share-recent-title {
    font-size: 1em;
    font-weight: normal;
    opacity: 0.8;
    margin: 0 0 12px;
}

/* Large targets: a controller ray is less precise than a mouse. */
.share-recent-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
}

.share-tile {
    position: relative;
    border-radius: 12px;
    background-color: var(--bg-color-2);
    transition: background-color var(--motion-fast) var(--motion-ease);
}

.share-tile:hover {
    background-color: var(--bg-color-3);
}

.share-tile-link {
    display: block;
    padding: 9px;
    border-radius: 12px;
    color: inherit;
    text-decoration: none;
}

.share-tile-link:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.share-tile-image {
    aspect-ratio: 16 / 10;
    border-radius: 6px;
    overflow: hidden;
    background-color: var(--bg-color-1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.share-tile-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.share-tile-placeholder {
    font-size: 0.85em;
    opacity: 0.6;
}

.share-tile-name {
    margin-top: 9px;
    font-size: 1.05em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.share-tile-meta {
    margin-top: 3px;
    font-size: 0.8em;
    opacity: 0.6;
}

.share-tile-remove {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 999px;
    background-color: rgba(0, 0, 0, 0.6);
    color: #ffffff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.share-tile-remove:hover {
    background-color: var(--bg-color-danger);
}

.share-tile-remove:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}
