/* =========================================================== developer achievements: split view
   Studio's dark theme, recoloured violet (Studio's blue selection becomes the site violet).
   Left: the title, then the games in a small Studio viewport: tool palette + two tilted cards. Right: a viewport where the
   selected game's item-buyer machine is built in 3D (static/js/roblox-machine.js), with the
   game's creator coverage in a small floating window over the viewport's corner.
   Markup: templates/pages/roblox_stats.html (.dev-*). Behaviour: setupDeveloperAchievements and
   setupDeveloperMachine in static/js/roblox-stats.js. The site's global rule strips shadows, so
   shadows here need !important. */

body .roblox-stats-page .roblox-developer-achievements {
    --dv-ground: #131116;
    --dv-panel: #1e1b23;
    --dv-panel-raised: #26222c;
    --dv-hover: #2d2834;
    --dv-line: #37323f;
    --dv-ink: #efeaf6;
    --dv-muted: #a59eb1;
    --dv-faint: #6f6879;
    --dv-select: #a77bff;
    --dv-select-strong: #8a52f0;
    --dv-select-tint: rgba(167, 123, 255, .16);
    --dv-font: Montserrat, "Avenir Next", system-ui, sans-serif;
    --dv-shadow: 0 1.2rem 2.6rem rgba(0, 0, 0, .55), 0 .25rem .6rem rgba(0, 0, 0, .35);

    /* same scale as the two sections above it (event achievements: clamp(52rem, 88svh, 64rem)) */
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: clamp(52rem, 88svh, 64rem);
    padding: clamp(3.5rem, 6vw, 5.5rem) clamp(1rem, 4vw, 4.5rem) clamp(4.5rem, 7vw, 6.5rem);
    border-top: 0;
    background:
        linear-gradient(#050408, transparent 10rem),
        radial-gradient(48% 55% at 70% 48%, rgba(138, 82, 240, .13), transparent 70%),
        var(--dv-ground);
    color: var(--dv-ink);
    font-family: var(--dv-font);
}

/* Studio's baseplate grid, faint */
body .roblox-stats-page .roblox-developer-achievements::before {
    background:
        linear-gradient(90deg, rgba(255, 255, 255, .04) 1px, transparent 1px),
        linear-gradient(rgba(255, 255, 255, .04) 1px, transparent 1px);
    background-size: 4.5rem 4.5rem;
    opacity: 1;
    /* fades in below the section above, so no grid line sits on the join */
    -webkit-mask-image: linear-gradient(transparent, #000 12rem);
    mask-image: linear-gradient(transparent, #000 12rem);
}

body .roblox-stats-page .roblox-developer-achievements::after {
    background: radial-gradient(circle at 50% 50%, transparent 55%, rgba(8, 7, 10, .7));
}

/* ------------------------------------------------------------------ layout */

.dev-split {
    position: relative;
    display: grid;
    grid-template-columns: minmax(21rem, 30rem) minmax(0, 1fr);
    gap: clamp(1.5rem, 3vw, 3rem);
    align-items: stretch;
    width: 100%;
    max-width: 86rem;
    margin: 0 auto;
}

.dev-side {
    position: relative;
    z-index: 3;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2rem;
    min-width: 0;
}

.dev-title {
    margin: 0;
    color: #fff;
    /* the same face as "event achievements" above, so the two sections read as one page */
    font: 400 clamp(3.1rem, 5.6vw, 5.4rem)/.84 Didot, "Bodoni 72", "Bodoni MT", "Iowan Old Style", Georgia, serif;
    letter-spacing: -.06em;
    text-shadow: .04em .035em 0 rgba(120, 112, 140, .5);
}

/* ------------------------------------------------------------------ the games viewport
   The tool palette as a small Studio toolbar, then two tilted, overlapping cards on the section's
   own background. The gizmos fit inside the column and drags are limited, so nothing spills. The selected card comes to the front with Studio's selection box (violet here, where
   Studio uses blue) and the active tool's gizmo: red / green move arrows, scale knobs or rotate
   rings, after Studio's Next-Gen draggers (setupDeveloperAchievements). Blue also marks
   keyboard focus. */

body .roblox-stats-page .roblox-developer-achievements {
    --dv-red: #e0707f;
    --dv-green: #6fcf97;
    --dv-blue: #5aa9ff;
}

.dev-studio {
    display: grid;
    justify-items: start;
}

/* ---- the palette: a small Studio toolbar above the cards */
.dev-tools {
    display: flex;
    align-items: center;
    gap: .15rem;
    padding: .25rem;
    border: 1px solid var(--dv-line);
    border-radius: .5rem;
    background: var(--dv-panel-raised);
    box-shadow: 0 .6rem 1.4rem rgba(0, 0, 0, .4) !important;
}

.dev-tool {
    display: flex;
    align-items: center;
    gap: .35rem;
    padding: .4rem .6rem;
    border: 0;
    border-radius: .35rem;
    background: none;
    color: var(--dv-muted);
    font: 600 .74rem/1 var(--dv-font);
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease;
}

.dev-tool[hidden] {
    display: none;
}

.dev-tool svg {
    width: .95rem;
    height: .95rem;
    fill: currentColor;
}

.dev-tool:hover {
    background: var(--dv-hover);
    color: var(--dv-ink);
}

.dev-tool[aria-pressed="true"] {
    background: var(--dv-select-tint);
    color: #d6c2ff;
}

.dev-tool:focus-visible {
    outline: 2px solid var(--dv-blue);
    outline-offset: -2px;
}

/* ---- the viewport and its cards */
.dev-deck {
    position: relative;
    display: grid;
    justify-self: stretch;
    /* room round the cards for the selection box and a little drag */
    padding: 4.6rem 2.4rem 4.4rem;
}

.dev-deck-empty {
    margin: 0;
    color: var(--dv-faint);
}

.dev-card {
    --tilt: 0deg;
    position: relative;
    grid-area: 1 / 1;
    align-self: start;
    width: 84%;
    transform: rotate(var(--tilt));
    transition: transform .35s cubic-bezier(.2, .75, .25, 1);
}

.dev-card--1 {
    --tilt: -3deg;
    z-index: 2;
    justify-self: start;
}

.dev-card--2 {
    --tilt: 2.5deg;
    z-index: 1;
    justify-self: end;
    margin-top: 8rem;
}

.dev-card.is-selected {
    z-index: 5;
    --tilt: -1deg;
}

.dev-card--2.is-selected {
    --tilt: 1deg;
}

.dev-card-pick {
    position: relative;
    z-index: 2;
    display: grid;
    width: 100%;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--dv-line);
    border-radius: .5rem;
    background: var(--dv-panel-raised);
    box-shadow: 0 .9rem 2rem rgba(0, 0, 0, .5) !important;
    color: var(--dv-ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color .2s ease;
}

.dev-card.is-selected .dev-card-pick {
    cursor: default;
}

.dev-card:not(.is-selected) .dev-card-pick:hover {
    border-color: #4b4456;
}

.dev-card-pick:focus-visible {
    outline: 2px solid var(--dv-blue);
    outline-offset: 3px;
}

.dev-card-image {
    display: block;
    aspect-ratio: 16 / 9;
    background: var(--dv-panel);
}

.dev-card-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.dev-card-placeholder {
    display: grid;
    place-items: center;
    height: 100%;
    color: var(--dv-muted);
    font: 800 3.5rem/1 var(--dv-font);
}

.dev-card-copy {
    display: grid;
    gap: .3rem;
    min-width: 0;
    padding: .7rem .85rem .8rem;
}

.dev-card-name {
    font: 800 1.05rem/1.15 var(--dv-font);
    letter-spacing: -.01em;
}

.dev-card-desc {
    overflow: hidden;
    color: var(--dv-muted);
    font: 500 .74rem/1.4 var(--dv-font);
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* one plain line: white numbers, muted labels */
.dev-card-stats {
    display: flex;
    flex-wrap: wrap;
    gap: .1rem .75rem;
    margin-top: .15rem;
    color: var(--dv-faint);
    font: 500 .68rem/1.3 var(--dv-font);
}

.dev-card-stats span {
    white-space: nowrap;
}

.dev-card-stats b {
    color: var(--dv-ink);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* open on Roblox: a bare icon in the image's corner */
.dev-card-link {
    position: absolute;
    top: .4rem;
    right: .4rem;
    z-index: 4;
    display: grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: .3rem;
    color: #fff;
    background: rgba(10, 9, 13, .55);
    transition: background-color .15s ease;
}

.dev-card-link svg {
    width: .85rem;
    height: .85rem;
}

.dev-card-link:hover {
    background: rgba(10, 9, 13, .85);
}

.dev-card-link:focus-visible {
    outline: 2px solid var(--dv-blue);
    outline-offset: 2px;
}

/* Studio's selection box: a thin outline (violet here, where Studio uses light blue) */
.dev-card-frame {
    position: absolute;
    inset: -.45rem;
    z-index: 3;
    border: 1.5px solid var(--dv-select);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
}

.dev-card.is-selected .dev-card-frame {
    opacity: 1;
}



/* ------------------------------------------------------------------ gizmos
   Studio's draggers as they look in Studio, 2D like the card (X and Y only):
     move:   thick arrows with big cones on both sides of each axis, starting just outside the
             card's edges (red X, green Y)
     scale:  big flat circles set out past the middle of each edge
     rotate: a thick, slightly faceted ring round the card: Studio's Z ring, the one that spins a
             flat card in place (seen head on, its X and Y rings would only be lines)
   plus the pivot dot at the centre. The card's face carries the scale, so the handles stay
   crisp and follow its edges via --sx / --sy. Pointer drags only; nothing depends on them. */

body .roblox-stats-page .roblox-developer-achievements {
    --gz-x: rgb(204, 0, 0);
    --gz-y: rgb(0, 204, 0);
    --gz-z: rgb(0, 0, 170);
}

/* the card's face and selection box carry the scale */
.dev-card-pick,
.dev-card-frame {
    transform: scale(var(--sx, 1), var(--sy, 1));
}

.dev-gizmo {
    position: absolute;
    inset: 0;
    z-index: 4;
    container-type: size;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
}

.dev-studio[data-developer-tool="move"] .dev-card.is-selected .dev-gizmo--move,
.dev-studio[data-developer-tool="scale"] .dev-card.is-selected .dev-gizmo--scale,
.dev-studio[data-developer-tool="rotate"] .dev-card.is-selected .dev-gizmo--rotate {
    opacity: 1;
}

.dev-h--x { color: var(--gz-x); }
.dev-h--y { color: var(--gz-y); }
.dev-h--z { color: var(--gz-z); }

.dev-h:hover,
.dev-h.is-active {
    filter: brightness(1.3);
}

/* ---- move: from the centre, pointed by rotating; the shaft and cone start past the edge */
.dev-arrow {
    --len: 3.4rem;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    transform-origin: 0 0;
}

.dev-arrow--right,
.dev-arrow--left {
    --from: calc(50cqw * var(--sx, 1) + .85rem);
}

.dev-arrow--up,
.dev-arrow--down {
    --from: calc(50cqh * var(--sy, 1) + .85rem);
}

.dev-arrow--left { rotate: 180deg; }
.dev-arrow--up { rotate: -90deg; }
.dev-arrow--down { rotate: 90deg; }

.dev-arrow::before {
    position: absolute;
    /* the transparent border is a fatter grab area round the 6px shaft */
    top: -10px;
    left: calc(var(--from) - 7px);
    width: calc(var(--len) - 1.1rem);
    height: 6px;
    border: 7px solid transparent;
    border-radius: 10px;
    background: currentColor;
    background-clip: padding-box;
    content: "";
}

.dev-arrow::after {
    position: absolute;
    top: -.62rem;
    left: calc(var(--from) + var(--len) - 1.5rem);
    border-block: .62rem solid transparent;
    border-left: 1.5rem solid currentColor;
    content: "";
}

/* ---- scale: flat circles off each edge, following the card's own scale */
.dev-ball {
    position: absolute;
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 50%;
    background: currentColor;
    translate: -50% -50%;
}

.dev-ball--right,
.dev-ball--left { top: 50%; }
.dev-ball--top,
.dev-ball--bottom { left: 50%; }
.dev-ball--right { left: calc(50% + 50% * var(--sx, 1) + 1.75rem); }
.dev-ball--left { left: calc(50% - 50% * var(--sx, 1) - 1.75rem); }
.dev-ball--top { top: calc(50% - 50% * var(--sy, 1) - 1.75rem); }
.dev-ball--bottom { top: calc(50% + 50% * var(--sy, 1) + 1.75rem); }

/* ---- rotate: the ring round the card */
.dev-gizmo--rotate svg {
    position: absolute;
    top: 50%;
    left: 50%;
    width: calc(100cqw * max(var(--sx, 1), var(--sy, 1)) + 1.5rem);
    aspect-ratio: 1;
    overflow: visible;
    translate: -50% -50%;
}

.dev-h-ring {
    fill: none;
    stroke: currentColor;
    stroke-width: 5;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.dev-h-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 18;
    vector-effect: non-scaling-stroke;
}

/* ---- the pivot: a small white dot ringed in the selection colour */
.dev-pivot {
    position: absolute;
    top: 50%;
    left: 50%;
    width: .5rem;
    height: .5rem;
    border: 2px solid var(--dv-select);
    border-radius: 50%;
    background: #fff;
    translate: -50% -50%;
}

.dev-studio[data-developer-tool="move"] .dev-card.is-selected .dev-gizmo--move .dev-h,
.dev-studio[data-developer-tool="scale"] .dev-card.is-selected .dev-gizmo--scale .dev-h,
.dev-studio[data-developer-tool="rotate"] .dev-card.is-selected .dev-gizmo--rotate .dev-h {
    pointer-events: visiblePainted;
    touch-action: none;
    cursor: grab;
}

.dev-studio[data-developer-tool="move"] .dev-card.is-selected .dev-gizmo--move .dev-arrow {
    pointer-events: none;
}

.dev-studio[data-developer-tool="move"] .dev-card.is-selected .dev-gizmo--move .dev-arrow::before,
.dev-studio[data-developer-tool="move"] .dev-card.is-selected .dev-gizmo--move .dev-arrow::after {
    pointer-events: auto;
}

.dev-studio.is-dragging,
.dev-studio.is-dragging * { cursor: grabbing !important; }

@media (prefers-reduced-motion: reduce) {
    .dev-card {
        transition: none;
    }
}

.dev-media-arrow:focus-visible,
.dev-media-pip:focus-visible {
    outline: 2px solid var(--dv-select);
    outline-offset: 2px;
    border-radius: .45rem;
}

/* ------------------------------------------------------------------ viewport + machine */

.dev-viewport {
    position: relative;
    z-index: 1;
    min-width: 0;
    min-height: 42rem;
}

.dev-machine {
    position: absolute;
    inset: -2rem -1rem 0 -2rem;
    margin: 0;
}

.dev-machine-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: pan-y;
}

.dev-machine-canvas.is-grabbing {
    cursor: grabbing;
}

.dev-machine-canvas.is-over-button {
    cursor: pointer;
}

/* the real YouTube player, warped onto the (still) machine's screen with the matrix3d set by
   roblox-machine.js; hidden while the machine moves */
.dev-machine-video {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    background: #000;
    cursor: auto;
}

/* hidden, but still rendered: a YouTube player that isn't rendered (display: none) ignores
   commands, so switching games while it was hidden left the old video playing */
.dev-machine-video[hidden] {
    display: block;
    visibility: hidden;
    pointer-events: none;
}

.dev-machine-video iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

/* larger than its box (sized and placed by roblox-machine.js) so a turned machine and its shadow
   fade out instead of being cut off; drags and clicks stay on the box itself */
.dev-machine-canvas canvas {
    position: absolute;
    display: block;
    pointer-events: none;
}

/* the caption is for screen readers only; its one control, the keyboard "next video", shows in
   the corner while it has keyboard focus */
.dev-machine-tag {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
}

.dev-machine-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* keyboard / screen-reader way to the next video (the green button on the machine does the same):
   out of sight until it has keyboard focus */
.dev-machine-next:not(:focus-visible) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.dev-machine-next {
    display: inline-flex;
    gap: .3rem;
    padding: .3rem .55rem;
    border: 1px solid var(--dv-line);
    border-radius: .25rem;
    background: var(--dv-panel-raised);
    color: var(--dv-ink);
    font: 600 .66rem/1 var(--dv-font);
    cursor: pointer;
    pointer-events: auto;
}

.dev-machine-next:hover {
    background: var(--dv-hover);
}

.dev-machine-next:focus-visible {
    outline: 2px solid var(--dv-select);
    outline-offset: 2px;
}

.dev-machine-next[hidden] {
    display: none;
}

.dev-machine-next b {
    color: var(--dv-select);
}

/* ------------------------------------------------------------------ creator coverage window
   Only a fallback now: the videos play on the 3D machine's screen. This window shows if the 3D
   machine can't load (no WebGL, module error). */

.dev-media {
    display: none;
    position: absolute;
    bottom: -2.5rem;
    left: -3.5rem;
    z-index: 4;
    width: min(22rem, 50%);
    padding: 0 .35rem .35rem;
    border: 1px solid var(--dv-line);
    border-radius: .7rem;
    background: var(--dv-panel);
    rotate: -2deg;
    box-shadow: var(--dv-shadow) !important;
}

.dev-machine[data-machine-ready="failed"] ~ .dev-media {
    display: block;
}

.dev-media-bar {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: 0;
    padding: .55rem .35rem .5rem;
    color: var(--dv-ink);
    font: 600 .72rem/1 var(--dv-font);
}

.dev-media-screen {
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: .4rem;
    background: #0c0b0e;
}

.dev-media-slide,
.dev-media-slide iframe,
.dev-media-slide img {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    object-fit: cover;
}

.dev-media-empty {
    display: grid;
    place-content: center;
    gap: .25rem;
    height: 100%;
    margin: 0;
    padding: 1rem;
    color: var(--dv-muted);
    font-size: .74rem;
    text-align: center;
}

.dev-media-empty strong {
    color: var(--dv-ink);
    font-size: .85rem;
}

.dev-media-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .45rem .15rem .1rem;
}

.dev-media-arrow {
    padding: .2rem .5rem;
    border: 1px solid var(--dv-line);
    border-radius: .35rem;
    background: var(--dv-panel-raised);
    color: var(--dv-ink);
    font: 700 .8rem/1 var(--dv-font);
    cursor: pointer;
}

.dev-media-arrow:hover {
    background: var(--dv-hover);
}

.dev-media-pips {
    display: flex;
    gap: .35rem;
}

.dev-media-pip {
    width: .5rem;
    height: .5rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #4a4452;
    cursor: pointer;
}

.dev-media-pip.is-active {
    background: var(--dv-select);
}

/* ------------------------------------------------------------------ narrow screens:
   title, then the machine, then the games, then the coverage window */

@media (max-width: 860px) {
    body .roblox-stats-page .roblox-developer-achievements {
        min-height: 0;
    }

    .dev-split {
        grid-template-columns: minmax(0, 1fr);
        gap: 1.2rem;
    }

    .dev-side,
    .dev-viewport {
        display: contents;
    }

    .dev-title { order: 1; }
    .dev-machine { order: 2; }
    /* the cards stacked, no overlap and no viewport chrome; the palette and gizmos are a pointer
       toy, left out here */
    .dev-studio {
        display: contents;
    }

    .dev-deck {
        order: 3;
        display: flex;
        flex-direction: column;
        gap: 1.6rem;
        padding: .6rem .7rem .5rem;
        background: none;
    }

    .dev-card-desc {
        white-space: normal;
    }

    .dev-card,
    .dev-card--2 {
        width: 100%;
        margin: 0;
    }

    .dev-tools,
    .dev-gizmo {
        display: none;
    }


    .dev-machine {
        position: relative;
        inset: auto;
        height: clamp(15rem, 62vw, 24rem);
        margin: 0 -1rem;
    }

    .dev-media {
        position: relative;
        bottom: auto;
        left: auto;
        order: 4;
        width: 100%;
        rotate: none;
    }
}
