/*
 * First Spark audiobook — the 3D jewel case, the narrator medallion and the
 * sample player. Shared by the ROTF and PFE sites, so it carries its own
 * colours rather than leaning on either site's variables.
 *
 * The case is a real CSS box (front, back, four edges) inside a perspective,
 * sized in container units so the edge faces can be pushed out by half the
 * case's width with translateZ — which only takes lengths, not percentages.
 */

.abx {
    --ab-ember: #f36a20;
    --ab-gold: #c9a55a;
    --ab-night: #0a0612;
    --ab-ry: -24deg;
    --ab-rx: 7deg;
    --ab-depth: 16px;

    container-type: inline-size;
    perspective: 1400px;
    perspective-origin: 50% 40%;
}

.abx-stage {
    --ab-w: min(74cqi, 340px);
    position: relative;
    width: var(--ab-w);
    aspect-ratio: 1;
    margin: 0 auto;
    transform-style: preserve-3d;
    transform: rotateY(var(--ab-ry)) rotateX(var(--ab-rx));
    transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ---- the case --------------------------------------------------------- */

.abx-face {
    position: absolute;
    backface-visibility: hidden;
}

.abx-front,
.abx-back {
    inset: 0;
    border-radius: 5px;
}

.abx-front {
    transform: translateZ(calc(var(--ab-depth) / 2));
    background: #08080b;
    overflow: hidden;
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.16),
        inset 0 0 0 3px rgba(0, 0, 0, 0.6);
}

/* The insert sits under the clear lid, inset from the hinge on the left. */
.abx-front img {
    position: absolute;
    top: 3.5%;
    right: 3.5%;
    bottom: 3.5%;
    left: 10%;
    width: 86.5%;
    height: 93%;
    object-fit: cover;
    border-radius: 2px;
}

/* The hinge: ribbed plastic down the left of the lid. */
.abx-front::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 7.5%;
    background:
        repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0 2px, transparent 2px 7px),
        linear-gradient(90deg, #15151b, #2c2c35 45%, #111116);
    border-right: 1px solid rgba(255, 255, 255, 0.18);
    z-index: 1;
}

/* The lid's sheen — and a slow glint that crosses it while it is in view. */
.abx-front::after {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(115deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.04) 28%, transparent 46%),
        linear-gradient(115deg, transparent 40%, rgba(255, 255, 255, 0.22) 50%, transparent 60%) no-repeat;
    background-size: 100% 100%, 250% 100%;
    background-position: 0 0, 160% 0;
    z-index: 2;
    pointer-events: none;
}

.abx-back {
    transform: rotateY(180deg) translateZ(calc(var(--ab-depth) / 2));
    background: linear-gradient(135deg, #16161c, #050507);
}

.abx-edge {
    background: linear-gradient(180deg, #2a2a33, #0c0c10);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.abx-edge--left,
.abx-edge--right {
    top: 0;
    width: var(--ab-depth);
    height: 100%;
    left: calc(50% - var(--ab-depth) / 2);
}

.abx-edge--left {
    transform: rotateY(-90deg) translateZ(calc(var(--ab-w) / 2));
    background:
        repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.07) 0 2px, transparent 2px 6px),
        linear-gradient(90deg, #121217, #30303a, #121217);
}

.abx-edge--right {
    transform: rotateY(90deg) translateZ(calc(var(--ab-w) / 2));
}

.abx-edge--top,
.abx-edge--bottom {
    left: 0;
    width: 100%;
    height: var(--ab-depth);
    top: calc(50% - var(--ab-depth) / 2);
}

.abx-edge--top {
    transform: rotateX(90deg) translateZ(calc(var(--ab-w) / 2));
}

.abx-edge--bottom {
    transform: rotateX(-90deg) translateZ(calc(var(--ab-w) / 2));
}

/* The sigil's glow, cast behind the case, and a soft shadow beneath it. */
.abx-glow {
    position: absolute;
    inset: 12%;
    transform: translateZ(-60px);
    background: radial-gradient(circle at 50% 62%, rgba(243, 106, 32, 0.55), rgba(243, 106, 32, 0) 65%);
    filter: blur(28px);
    pointer-events: none;
}

.abx-floor {
    position: absolute;
    left: 8%;
    right: 8%;
    bottom: -9%;
    height: 14%;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.55), transparent 70%);
    transform: rotateX(90deg) translateZ(calc(var(--ab-w) * -0.05));
    filter: blur(6px);
    pointer-events: none;
}

/* ---- the narrator medallion ------------------------------------------ */

.abx-narrator {
    position: absolute;
    right: -11%;
    bottom: -9%;
    width: 42%;
    aspect-ratio: 1;
    margin: 0;
    transform: translateZ(64px);
    transform-style: preserve-3d;
}

.abx-narrator img {
    position: absolute;
    inset: 15%;
    width: 70%;
    height: 70%;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid var(--ab-ember);
    box-shadow:
        0 0 0 5px rgba(10, 6, 18, 0.85),
        0 0 28px rgba(243, 106, 32, 0.55),
        0 14px 30px rgba(0, 0, 0, 0.6);
}

.abx-narrator svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    animation: abx-spin 22s linear infinite;
}

.abx-narrator text {
    fill: #fff;
    font-family: 'Cinzel', Georgia, serif;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    paint-order: stroke;
    stroke: rgba(10, 6, 18, 0.9);
    stroke-width: 3px;
}

@keyframes abx-spin {
    to { transform: rotate(360deg); }
}

@keyframes abx-glint {
    from { background-position: 0 0, 160% 0; }
    to { background-position: 0 0, -60% 0; }
}

/* ---- STATIC: always showing (the audiobook section) -------------------- */

.abx--static {
    /* Sized from the viewport, not the container: the static case sits in
       shrink-to-fit columns (a centred grid item on mobile), and a size
       container contributes no width to those, so it would collapse to 0. */
    container-type: normal;
    width: fit-content;
    margin-inline: auto;
    padding: 1rem 3.5rem 3.5rem 1rem;
}

.abx--static .abx-stage {
    --ab-w: min(300px, 62vw);
}

.abx--static .abx-front::after {
    animation: abx-glint 5.5s ease-in-out 1.2s infinite;
}

/* ---- OVERLAY: swapped in over a book cover while its button is hovered -- */

.ab-host {
    position: relative;
}

.ab-host [data-ab-fade] {
    transition: opacity 0.45s ease, filter 0.45s ease, transform 0.6s ease;
}

.ab-host.ab-on [data-ab-fade] {
    opacity: 0.12;
    filter: blur(3px) saturate(0.6);
}

.abx--overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: grid;
    place-items: center;
    padding-right: 8%;
    pointer-events: none;
}

.abx--overlay.abx--top {
    place-items: start center;
    padding-top: 9%;
}

.abx--overlay .abx-stage {
    --ab-w: min(66cqi, 320px);
    opacity: 0;
    transform: rotateY(-95deg) rotateX(12deg) translateZ(-160px) scale(0.7);
    transition: transform 0.8s cubic-bezier(0.2, 0.9, 0.25, 1.1), opacity 0.35s ease;
}

.abx--overlay.abx--top .abx-stage {
    --ab-w: min(52cqi, 250px);
}

.ab-on .abx--overlay .abx-stage {
    opacity: 1;
    transform: rotateY(var(--ab-ry)) rotateX(var(--ab-rx));
}

.abx--overlay .abx-narrator {
    opacity: 0;
    transform: translateZ(64px) scale(0.3) rotate(-30deg);
    transition: transform 0.55s cubic-bezier(0.3, 1.6, 0.5, 1) 0.32s, opacity 0.3s ease 0.32s;
}

.ab-on .abx--overlay .abx-narrator {
    opacity: 1;
    transform: translateZ(64px);
}

.ab-on .abx--overlay .abx-front::after {
    animation: abx-glint 1.6s ease-out 0.45s 1 both;
}

@media (prefers-reduced-motion: reduce) {
    .abx-stage,
    .abx--overlay .abx-stage,
    .ab-on .abx--overlay .abx-stage,
    .abx--overlay .abx-narrator,
    .ab-on .abx--overlay .abx-narrator {
        transition: opacity 0.3s ease;
        transform: rotateY(-18deg) rotateX(5deg);
    }

    .abx-narrator,
    .abx--overlay .abx-narrator,
    .ab-on .abx--overlay .abx-narrator {
        transform: translateZ(64px);
    }

    .abx-narrator svg,
    .abx-front::after {
        animation: none !important;
    }
}

/* ---- the sample player ------------------------------------------------ */

.ab-sample {
    --ab-ember: #f36a20;
    --ab-gold: #c9a55a;
    display: flex;
    align-items: center;
    gap: 0.9rem;
    width: 100%;
    max-width: 420px;
    margin: 1.5rem 0;
    padding: 0.7rem 1rem 0.7rem 0.7rem;
    border: 1px solid rgba(201, 165, 90, 0.35);
    border-radius: 999px;
    background: rgba(10, 6, 18, 0.55);
    backdrop-filter: blur(6px);
    color: #fff;
    text-align: left;
    font-family: inherit;
}

.ab-sample--light {
    background: #fff;
    color: #2c2c2c;
    border-color: rgba(201, 165, 90, 0.55);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
}

.ab-sample-play {
    position: relative;
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ab-gold), var(--ab-ember));
    color: #140d06;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ab-sample-play:hover,
.ab-sample-play:focus-visible {
    transform: scale(1.06);
    box-shadow: 0 0 0 4px rgba(243, 106, 32, 0.25);
    outline: none;
}

.ab-sample-play svg {
    width: 18px;
    height: 18px;
}

.ab-sample-play .ab-icon-pause,
.ab-sample.is-playing .ab-sample-play .ab-icon-play {
    display: none;
}

.ab-sample.is-playing .ab-sample-play .ab-icon-pause {
    display: block;
}

/* A slow pulse while it plays, so the page says where the sound is coming from. */
.ab-sample.is-playing .ab-sample-play::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--ab-ember);
    animation: ab-pulse 1.6s ease-out infinite;
}

@keyframes ab-pulse {
    from { transform: scale(1); opacity: 0.8; }
    to { transform: scale(1.45); opacity: 0; }
}

.ab-sample-body {
    flex: 1 1 auto;
    min-width: 0;
}

.ab-sample-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.3;
}

.ab-sample-sub {
    display: block;
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 0.1rem;
}

/* Equaliser bars, only while playing. */
.ab-eq {
    display: none;
    gap: 2px;
    align-items: flex-end;
    height: 12px;
}

.ab-sample.is-playing .ab-eq {
    display: inline-flex;
}

.ab-eq span {
    width: 3px;
    background: var(--ab-ember);
    border-radius: 1px;
    animation: ab-eq 0.9s ease-in-out infinite;
}

.ab-eq span:nth-child(2) { animation-delay: -0.3s; }
.ab-eq span:nth-child(3) { animation-delay: -0.6s; }

@keyframes ab-eq {
    0%, 100% { height: 3px; }
    50% { height: 12px; }
}

.ab-sample-track {
    --ab-pct: 0%;
    display: block;
    width: 100%;
    height: 6px;
    margin: 0.55rem 0 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--ab-gold), var(--ab-ember)) 0 0 / var(--ab-pct) 100% no-repeat,
        rgba(201, 165, 90, 0.25);
    appearance: none;
    cursor: pointer;
}

.ab-sample-track:focus-visible {
    outline: 2px solid var(--ab-ember);
    outline-offset: 3px;
}

.ab-sample-track::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--ab-ember);
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.ab-sample-track::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--ab-ember);
    border: 2px solid #fff;
}

.ab-sample-time {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.72rem;
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
    .ab-eq span,
    .ab-sample.is-playing .ab-sample-play::after {
        animation: none;
    }
}

/* ---- the Audible store picker ----------------------------------------- */

.audible-stores {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.9rem;
    margin-top: 1.25rem;
    font-size: 0.82rem;
}

.audible-stores span {
    opacity: 0.6;
}

.audible-stores a {
    color: inherit;
    opacity: 0.75;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: opacity 0.2s ease, border-color 0.2s ease;
}

.audible-stores a:hover,
.audible-stores a:focus-visible,
.audible-stores a.is-current {
    opacity: 1;
    border-bottom-color: #f36a20;
}
