/*
 Gems in the workshop: the opal gem, the ring round a photo, and the small
 reasons under something that can't be used.

 The opal colours are the app's (OpalPalette in opalGemView.dart): soft cyan,
 pink, pale gold and lilac. The cut ring is the same loop dulled towards a
 grey-lilac, a little less so in the dark so it still shows.
*/
:root,
html[data-theme="light"] {
    --opal-cyan: #A9E4EE;
    --opal-pink: #F5C3D8;
    --opal-gold: #F6E7B8;
    --opal-lilac: #D2C6F1;
    --opal-shade: rgba(142, 134, 179, 0.45);
    --opal-edge: rgba(142, 134, 179, 0.55);
    --opal-glow: rgba(210, 198, 241, 0.75);
    --opal-ring: conic-gradient(var(--opal-cyan), var(--opal-pink), var(--opal-gold), var(--opal-lilac), var(--opal-cyan));
    --opal-ring-reversed: conic-gradient(var(--opal-cyan), var(--opal-lilac), var(--opal-gold), var(--opal-pink), var(--opal-cyan));
    --opal-ring-muted: conic-gradient(#B5C9D9, #D3BCD0, #D4CAC3, #C5BDDA, #B5C9D9);
    --opal-ring-hairline: 0 0 0 0.8px var(--opal-shade);
}

html[data-theme="dark"] {
    --opal-shade: rgba(210, 198, 241, 0.25);
    --opal-edge: rgba(240, 232, 255, 0.35);
    --opal-glow: rgba(210, 198, 241, 0.35);
    --opal-ring-muted: conic-gradient(#B2D0DE, #DCBED2, #DCD1C1, #C9BFE0, #B2D0DE);
    --opal-ring-hairline: none;
}

/* ---------------------------------------------------------------- Rings */

/*
 Wraps a round photo. The ring is drawn over the photo's own edge, inside
 the space it already takes, so a photo with a ring lays out exactly like
 one without. Never animated.
*/
.gem-ring {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
    border-radius: 50%;
    line-height: 0;
    vertical-align: middle;
}

.gem-ring--cut::after,
.gem-ring--brilliant::after,
.gem-ring--radiant::after,
.gem-ring--radiant::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    pointer-events: none;
    padding: var(--gem-ring-w, 2px);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask-composite: exclude;
}

.gem-ring--cut::after {
    background: var(--opal-ring-muted);
}

.gem-ring--brilliant::after,
.gem-ring--radiant::after {
    background: var(--opal-ring);
}

/* A hairline round the outside, so the pastel ring keeps its edge on a white page. */
.gem-ring--brilliant,
.gem-ring--radiant {
    box-shadow: var(--opal-ring-hairline);
}

/* Radiant: a thin second ring inside the first, its colours running the other way. */
.gem-ring--radiant::before {
    inset: calc(var(--gem-ring-w, 2px) * 1.5);
    padding: max(1px, calc(var(--gem-ring-w, 2px) * 0.45));
    background: var(--opal-ring-reversed);
}

/* A photo inside a ring keeps its size but gives its own border to the ring. */
.gem-ring--cut > img,
.gem-ring--cut > span,
.gem-ring--brilliant > img,
.gem-ring--brilliant > span,
.gem-ring--radiant > img,
.gem-ring--radiant > span {
    border-color: transparent !important;
}

/* ------------------------------------------------------------- The gem */

.opal-gem {
    position: relative;
    display: inline-block;
    flex-shrink: 0;
    line-height: 0;
    vertical-align: middle;
    --gem-lx: 32%;
    --gem-ly: 26%;
}

.opal-gem__svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.opal-gem--rough .opal-gem__svg {
    filter: saturate(0.45) brightness(0.97);
}

.opal-gem--cut .opal-gem__svg {
    filter: saturate(0.85);
}

.opal-gem--brilliant .opal-gem__svg,
.opal-gem--radiant .opal-gem__svg {
    filter: drop-shadow(0 0 4px var(--opal-glow));
}

.opal-gem__base {
    fill: var(--opal-lilac);
}

.opal-gem__facet {
    stroke: var(--opal-edge);
    stroke-width: 0.6;
    stroke-linejoin: round;
    animation: opal-drift 14s linear infinite;
}

.opal-gem__lift {
    fill: #FFFFFF;
    pointer-events: none;
}

.opal-gem__outline {
    fill: none;
    stroke: var(--opal-shade);
    stroke-width: 1.2;
    stroke-linejoin: round;
}

/* The light that follows the pointer, clipped to the gem's outline. */
.opal-gem__light,
.opal-gem__sweep {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.opal-gem__light {
    background: radial-gradient(circle at var(--gem-lx) var(--gem-ly), rgba(255, 255, 255, 0.85) 0, rgba(255, 255, 255, 0) 48%);
    opacity: 0.55;
}

.opal-gem--rough .opal-gem__light {
    opacity: 0.25;
}

.opal-gem--radiant .opal-gem__light {
    opacity: 0.75;
}

/* The highlight that crosses the gem every few seconds, from brilliant up. */
.opal-gem__sweep {
    background: linear-gradient(105deg, rgba(255, 255, 255, 0) 38%, rgba(255, 255, 255, 0.8) 50%, rgba(255, 255, 255, 0) 62%);
    background-size: 300% 100%;
    background-repeat: no-repeat;
    background-position: 0% 0;
    animation: opal-sweep 5.5s ease-in-out infinite;
}

/* A few sparkles round a radiant gem. */
.opal-gem__sparkle {
    position: absolute;
    width: 14%;
    height: 14%;
    pointer-events: none;
    background: #FFFFFF;
    clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
    filter: drop-shadow(0 0 2px var(--opal-glow));
    transform: scale(0);
    animation: opal-twinkle 3.2s ease-in-out infinite;
}

.opal-gem__sparkle--1 { left: 10%; top: 18%; animation-delay: 0s; }
.opal-gem__sparkle--2 { left: 76%; top: 10%; animation-delay: -1.1s; }
.opal-gem__sparkle--3 { left: 64%; top: 58%; animation-delay: -2.2s; width: 10%; height: 10%; }

html[data-theme="light"] .opal-gem__sparkle {
    background: #FFFFFF;
    filter: drop-shadow(0 0 1px var(--opal-shade)) drop-shadow(0 0 3px var(--opal-glow));
}

@keyframes opal-drift {
    0% { fill: var(--opal-cyan); }
    25% { fill: var(--opal-pink); }
    50% { fill: var(--opal-gold); }
    75% { fill: var(--opal-lilac); }
    100% { fill: var(--opal-cyan); }
}

@keyframes opal-sweep {
    0% { background-position: 0% 0; }
    30% { background-position: 100% 0; }
    100% { background-position: 100% 0; }
}

@keyframes opal-twinkle {
    0%, 100% { transform: scale(0) rotate(0deg); opacity: 0; }
    20% { transform: scale(1) rotate(20deg); opacity: 1; }
    40% { transform: scale(0) rotate(45deg); opacity: 0; }
}

/* Still: for a small gem next to a number, and for anyone who asks for less motion. */
.opal-gem--still .opal-gem__facet,
.opal-gem--still .opal-gem__sweep {
    animation: none;
}

.opal-gem--still .opal-gem__sweep {
    display: none;
}

.opal-gem--still .opal-gem__sparkle {
    animation: none;
    transform: scale(0.8);
    opacity: 0.9;
}

@media (prefers-reduced-motion: reduce) {
    .opal-gem__facet,
    .opal-gem__sweep {
        animation: none !important;
    }

    .opal-gem__sweep {
        display: none;
    }

    .opal-gem__sparkle {
        animation: none !important;
        transform: scale(0.8);
        opacity: 0.9;
    }
}

/* ----------------------------------------------- Greyed out, and why */

.greyed-reason {
    display: block;
    font-size: 0.75rem;
    line-height: 1.3;
    color: var(--nv-muted);
}
